#include<stdio.h>



int main(){
  int time[1000];
  char name[1000][10];
  int head=0,tail=0,n,q;
  int i,total=0,flag=1;
  
  // input
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",name[i],&time[i]);
  }
  
  // execute
  while(1){
    flag = 0;
    for(i=0;i<n;i++){
      if(time[i] <= q && time[i] > 0){
	total += time[i];
	time[i] = 0;
	printf("%s %d\n",name[i],total);
      }
      else if(time[i] > q){
	total += q;
	time[i] -= q;
	flag = 1;
      }
    }
    if(flag == 0) break;
  }
  
  
  return 0;
}