#include <stdio.h>
#include <stdlib.h>
typedef struct
{
	char name[10];
	int time;	
}queue;
int main(int argc, char *argv[])
{
	int n,q,j,i=-1;
	int top=-1,totaltime=0;
	int *b;
	queue *a;
	scanf("%d%d",&n,&q);
	a=(queue *)malloc(sizeof(queue)*n);//?????°??? 
	b=(int *)malloc(sizeof(int)*2*n);//??????????????¶??´ 
	for(j=0;j<n;j++)
	scanf("%s%d",a[j].name,&a[j].time);
   	while(top!=n-1)
 	{
   		for(j=0;j<n;j++)
  		{
   			if(a[j].time==0)
				continue;
			if(a[j].time<=q)
			{
				totaltime=a[j].time+totaltime;	
				a[j].time=0;
				i=i+2;
				b[i-1]=j;
				b[i]=totaltime;
				top++;
			}
			else
			{
				totaltime=q+totaltime;
				a[j].time=a[j].time-q;		
			}
						
   		}	
   	} 
   	for(i=0;i<2*n;i=i+2)
   	{
   	j=b[i];
   	printf("%s %d\n",a[j].name,b[i+1]);
   	}
	return 0;
}