#include<stdio.h>
 
typedef struct process{
  char name[10];
  int time;
}P;
 
main(){
  int n, q, i, j, flag=0, temp=0;
  P pro[1001];
  int counter=0;
 
  scanf("%d%d",&n,&q);
  if(n<1||n>1000||q<1||q>1000) return 0; 
 
  for(i=0;i<n;i++){
    scanf("%s%d",pro[i].name,&pro[i].time);
  }
 
  while(1){                            
    for(i=0;i<n;i++){
      pro[i].time=pro[i].time-q;
      if(pro[i].time<=0){
        counter=counter+(pro[i].time+q);
        printf("%s %d\n",pro[i].name,counter);
        for(j=i;j<n-1;j++){
          pro[j]=pro[j+1];
        }
        n--;                       
        i--;
      } else counter=counter+q;
    }
    if(n==0)break;              
  }
  return 0;
}