#include<stdio.h>
typedef struct{
  int time;
  char names[10];
}pr;
int main(){
  int i,n,q,time,sum=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==0)break;
    if(p[0].time<=time){
      sum+=p[0].time;
      printf("%s %d\n",p[0].names,sum);
      for(i=1;i<n;i++)p[i-1]=p[i];
      n--;
    }
    else {
      sum+=time;
      p[0].time-=time;
      array=p[0];
      for(i=0;i<n;i++)p[i-1]=p[i];
      p[i-1]=array;
    }
  }
  return 0;
}

