#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void){

  int i,j,count=0,n,q;
  int time[50000];
  char *name[1000000];

  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",name[i],&time[i]);
  }
  while(1){
    if(time[i]=='\0')break;
    if(time[i]>q){
      time[n]=time[i]-q;
      n++;
      count+=q;
      strcpy(name[n],name[i]);
     
      //    time[i]=NULL;
    }
      
    else if(time[i]==q){
	count+=q;
	
	//	time[i]=NULL;
       printf("%s%d",name[i],count);
}
    else if(time[i]<q){
      count+=time[i];
      //  time[i]=NULL;
       printf("%s%d",name[i],count);
    }
  }
  return 0;
}