#include<stdio.h>

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

int main(){
  int head=0,tail,q,timesum=0,i,num;
  Process n[100000];
  scanf("%d%d",&num,&q);
  for(i=0;i<num;i++){
    scanf("%s",n[i].name);
    scanf("%d",&n[i].time);
  }
  
  tail=num;
  while(1){
    if(head==tail) {  break;}
   
    if(n[head].time>q){
      timesum+=q;
      n[head].time-=q;
      n[tail]=n[head];
      head++;
      tail++;
      if(head==100000)head=0;
      if(tail==100000)tail=0;
    }
    else if (n[head].time<=q){
  

      timesum+=n[head].time;
      
      
       printf("%s %d\n",n[head].name,timesum);
      head++;
      if(head==100000) head=0;
    }
  }
 
  return 0;
}
  
      
      
	
    

