#include<stdio.h>
#define MAX 100005
typedef struct queue {
	char name[11];
	int time;
} P;

int head, tail;
P p[MAX];

P dequeue()
{	
	P x = p[head];
	head = (head + 1) % MAX;
	return x;
}

void enqueue(P x)
{	
	p[tail] = x;
	tail = (tail + 1) % MAX;
}

int main()
{	
	int i, n, q;
	int c, timer = 0;
	P p1;

	scanf("%d %d", &n, &q);

	for(i = 0; i < n; i++)
		scanf("%s %d", p[i].name, &p[i].time);

	head = 1;
	tail = n + 1;
	
	while(head != tail) {
		p1 = dequeue();
		c = q < p1.time ? q : p1.time;
		p1.time -= c;
		timer += c;
		if(p1.time > 0)
			enqueue(p1);
		else
			printf("%s %d\n", p1.name, timer);
	}
    return 0;
}