#include <stdio.h>

int main(){

  int n,q,time[100000],i,maxi,alltime=0,count=0;
  char name[100000][50];

  scanf("%d%d",&n,&q);

  for(i=0;i<n;i++){
    scanf("%s%d",name[i],&time[i]);
    //if(maxtime<time[i]){
      //maxtime = time[i];
      //maxi = i;
    //    }
  }
  //  printf("%s\n",name[maxi]);
  for(i=0;i<n;i++){
    // printf("%d\n",i);
    if(time[i] <= q && time[i] != 0){
      alltime += time[i];
      printf("%s %d\n",name[i],alltime);
      time[i] = 0;
      count++;
    }else if(time[i] != 0){
      alltime += q;
      time[i] -= q;
    }
    if(count==n)break;
    if(i==n-1)i=-1;

    //if(time[maxi]==0)break;

  }


  return 0;
}