#include<stdio.h>
#define N 1000001
typedef struct
{
  char name[10];
  int time;
} P;//structure of process
P p[N];
int top=0,bottom;//points for queue
void enqueue(P);
void dequeue();
int main(void)
{
  int i;//counter
  int q;//quantum
  int sum=0;//sum of time
  scanf("%d%d",&bottom,&q);
  for(i=0;i<bottom;i++) scanf("%s%d",p[i].name,&p[i].time);
  while(top!=bottom)
    {
      if(p[top].time>q)
	{
	  sum+=q;
	  p[top].time-=q;
	  enqueue(p[top]);
	  dequeue();
	}
      else
	{
	  sum+=p[top].time;
	  printf("%s %d\n",p[top].name,sum);
	  dequeue();
	}
    }
  return 0;
}
void enqueue(P enp)
{
  p[bottom]=enp;
  bottom++;
  if(bottom>=N) bottom=0;
}
void dequeue(void)
{
  top++;
  if(top>=N) top=0;
}


