#include<stdio.h>
#define N 100000
typedef struct{
  int time;
  char name[11];
}pro;
main(){
  pro dat1[N],dat2[N];
  int i,q,stime = 0,count1 = 0,count2 = 0,count3;
  scanf("%d %d",&count1,&q);
  for(i = 0;i < count1;i++)
    scanf("%s %d",dat1[i].name,&dat1[i].time);

  count3 = count1;

  while(count3 > 0){
    count2 = 0;
    for(i = 0;i < count1;i++){
      if(dat1[i].time <= q){
	stime += dat1[i].time;
	printf("%s %d\n",dat1[i].name,stime);
	count3--;
      }
      else{
	stime += q;
	dat1[i].time -= q;
	dat2[count2] = dat1[i];
	printf("%d\n",dat1[i].time);
	count2++;
      }
    }
    count1 = 0;
    for(i = 0;i < count2;i++){
      if(dat2[i].time <= q){
	stime += dat2[i].time;
	count3--;
      }
      else{
	stime += q;
	dat2[i].time -= q;
	dat1[count1] = dat2[i];
	count1++;
      }
    }
  }
return 0;
}