#include <stdio.h>
#include <string.h>

#define LEN 100005
int head, tail, n;

typedef struct {
	char name[100];
	int time;
} Data;

Data data[LEN];
void enqueue(Data x)
{
	data[tail] = x;
	tail = (tail + 1) % LEN;
}

Data dequeue()
{
	Data x = data[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b)
{
	return a < b ? a : b;
}


int isEmpty()
{
	return head == tail;
}
int main()
{
	int i,q,c;
	int sum_time = 0;
	Data temp;
	scanf("%d %d", &n, &q);
	head = 0;
	tail = n;
	for (i = 0; i < n; i++) {
		scanf("%s %d", &data[i].name, &data[i].time);
	}
	while (!isEmpty()) {
		temp = dequeue();
		c = min(temp.time, q);
		temp.time -= c;
		sum_time += c;
		if (temp.time > 0) {
			enqueue(temp);
		}
		else {
			printf("%s %d\n", temp.name, sum_time);
		}
	}

	return 0;
}

