#include <stdio.h>

#define MAX 100000

typedef struct
{
  char name[10];
  int time;
}Process;

Process p[MAX];

int head=0,tail=0;

int main()
{
  int n,qt,pt,t=0,i;
  Process A;

  scanf("%d%d",&n,&qt);

  for(i=0;i<n;i++)
    {
      scanf("%s",p[i].name);
      scanf("%d",&p[i].time);
    }

  tail=n;
  
  while(head!=tail)
    {
      pt=p[head].time;
      p[head].time-=qt;
      if(p[head].time<=0)
	{
	  t+=pt;
	  printf("%s %d\n",p[head].name,t);
	  if( (head+1)==MAX )
	    {
	      head = 0;
	    }
	  else head++;
	}
      else
	{
	  t+=qt;
	  A=p[head];
	  if( (head+1)==MAX )
	    {
	      head = 0;
	    }
	  else head++;
	  p[tail]=A;
	  if(tail+1==MAX)tail=0;
	  else tail++;
	}
    }
  
  return 0;
}



