#include <stdio.h>
#define MAX 50000

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

math que[MAX];
int main() {
    int num,q,t,i,tmp,time;
  scanf("%d%d",&num,&q);
  for(i=0;i<num;i++){
    scanf("%s%d",que[i].name,&que[i].time);
  } 
  
  for(i=0,tmp=0,time=0;tmp<num;i=(i+1)%num) {
        if(que[i].time<=0) continue;
        t=q<que[i].time ? q : que[i].time;
        que[i].time -= t;
        time += t;
        if(que[i].time <= 0) {
         printf("%s %d\n", que[i].name, time);
         tmp++;
        }
  }
  return 0;
}
