#include<stdio.h>
#define LEN 1000000
typedef struct{
  char name[20];
  int time;
}Que;
Que que[LEN],Q;
int main()
{
  int N,i,q,head=0, tail=0,times=0;
  scanf("%d%d",&N,&q);
  for(i=0; i<N; i++){
      scanf("%s%d",Q.name,&Q.time);
      que[head]=Q;
      head++;
  }
  while(1){
      tail++;
      Q= que[tail-1];
      if(Q.time<=q){
	     times+=Q.time;
	     printf("%s %d\n", Q.name, times);
      }else{
    	  Q.time-=q;
    	  times+=q;
    	  que[head]=Q;
          head++;
      }
      if( head-tail==0)break;
  }
  return 0;
}
