#include<stdio.h>
#include<string.h>



typedef struct queue{
  char name[50];
  int time;
}Q;


Q queue[1000000];
int head,tail,count;


void enqueue(Q a){
  
  queue[tail]=a;
  tail=tail+1;
  
}


Q dequeue(){

  Q a=queue[head];
  head=head+1;
  return a;
  
}


int cal(int x,int y){
  if(x<y){return x;}
  else {return y;}
}


int main(void){

 
  int q;
 
  scanf("%d%d",&count,&q);


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

  
  head=0;
  tail=count;
  int add;
  int cost=0;
  int ans;
  Q tmp;

  while(tail>head){

    tmp=dequeue();
    ans=cal(q,tmp.time);

    //printf("%d\n",ans);

    tmp.time=tmp.time-ans;
    cost=cost+ans;

    //printf("I am %s. My surplus is %d. Cost is %d.\n\n",tmp.name,tmp.time,cost);
    
    if(tmp.time>0){enqueue(tmp);}

    else {printf("%s %d\n",tmp.name,cost);
    }
  }
 
  return 0;
}






