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

struct list{
	char name[15];
	int time;
};
struct list node[100005];

int main()
{
	int n,ti,T=0;
	int i=0;
	scanf("%d%d",&n,&ti);
	int coun=n;
	while(coun--)
	{
		scanf("%s %d",&node[i].name,&node[i].time);
		i++;
	}
	for(int head=0,tail=n;head!=tail;head=(head+1)%(n+1))
	{
		i=head;
		if(node[i].time<=ti)
		{
			T+=node[i].time;
			printf("%s %d\n",node[i].name,T);
			node[i].time=0;
		}
		else
		{
			T+=ti;
			node[tail].time=node[i].time-ti;
			strcpy(node[tail].name,node[i].name);
			tail=(tail+1)%(n+1);
		}
	}
	return 0;
}

