#include<stdio.h>
#include <string.h>
typedef struct{
  int time;
  char names[10];
}pr;
int main(){
  int i,n,q,time,sum=0,head=0;
  pr p[100000],array;
  scanf("%d %d",&n,&time);
  for(i=0;i<n;i++)scanf("%s %d",p[i].names,&p[i].time);
  while(1){
    if(n+1==head)break;
    if(p[head].time<=time){
      sum+=p[head].time;
      printf("%s %d\n",p[head].names,sum);
      head++;
    }
    else {
      sum+=time;
      p[head].time-=time;
      n++;
      p[i].time=p[head].time;
      strcpy(p[i].names,p[head].names);
      head++;
      
    }

  }
  return 0;
}

