#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
struct task
{
	char name[20];
	int time;
};
struct task queue[1000010];//队列
int main()
{
	int n,i,q,totaltime=0,len,head=1,tail=1;
	scanf("%d %d",&n,&q);
	for(i=1;i<=n;i++)
	{
		scanf("%s %d",queue[i].name,&queue[i].time);
		tail++;
	}
	while(head!=tail)
	{
		if(queue[head].time<=q)
		{
			totaltime+=queue[head].time;
			//puts(queue[head].name);
			len=strlen(queue[head].name);
			for(i=0;i<=len-1;i++)
				printf("%c",queue[head].name[i]);
			printf(" %d\n",totaltime);
			head++;
		}
		else
		{
			totaltime+=q;
			strcpy(queue[tail].name,queue[head].name);
			queue[tail].time=queue[head].time-q;
			tail++;
			head++;
		}
	}
	return 0;
}
