#include <stdio.h>
#define string 10
#define nMAX 100000

int main()
{
  int n, q, i;
  int time[nMAX],sumtime=0, flag[nMAX], flagcount=0;
  char name[nMAX][string];
  
  scanf("%d%d", &n, &q);
  
  for(i=0; i<n; i++){
    scanf("%s%d",name[i], &time[i]);
  }
  
  while(1){

    //printf("now\n");

    if(flagcount == n){
      break;
    }

     for(i=0; i<n; i++){

	 if(flag[i] == 1){
	   continue;
	 }

	 time[i]-=q;
	 sumtime+=q;

	 if(time[i] <= 0){
	   sumtime-=(0-time[i]);

	   flag[i] = 1;
	   flagcount++;

	   printf("%s %d", name[i], sumtime);
	   if(flagcount != n){
	     printf("\n");
	   }
	 }

     if(flagcount == n){
	 break;
       }
     }
  }
  
  printf("\n");
  return 0;
}