#include<stdio.h>
typedef struct p{
	char name[10];
	int time;
}p;
void 	enqueue(p a);
p dequeue();
p s[100005];
int head = 0;
int tail = 0;
int n;
int limit;
int total;
int main()
{
	scanf("%d", &n);
	scanf("%d", &limit);
	for(int i = 0; i < n; i++)
		scanf("%s %d",s[i].name,&s[i].time);
	for(int i = 0; i < n; i++)
		enqueue(s[i]);
	while(head != tail)
	{
		p tem =dequeue();
		if(tem.time<=limit)
		{
			total += tem.time;
			printf("%s %d\n",tem.name,total);
		}else{
			total += limit;
			tem.time -=limit;
			enqueue(tem);
		}
	}
}

void 	enqueue(p a)
{
	s[tail] = a;
	tail++;
	tail = tail%100005;
}

p dequeue()
{
	int tem = head;
	head ++;
	head = head%100005;
	return s[tem];
}

