#include <stdio.h>

int main(void){
  int n,q,time[100000],i,j=0,t=0;
  char name[100000][10];

  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",name[i],&time[i]);
  }
  i=0;
  while(j<n){
    if(time[i]==0){}
    else if(time[i]>q){
      t+=q;
      time[i]-=q;
    }
    else if(time[i]<=q && time[i]>0){
      t+=time[i];
      printf("%s %d\n",name[i],t);
      time[i]=0;
      j++;
    }
    i++;
    if(i>n) i=0;
  }
  return 0;
}
