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

int main()
{
  int n, q, i,j, num=0;
  int time[nMAX], anstime[nMAX], sumtime=0, flag[nMAX], flagcount=0;
  char name[nMAX][string], ansname[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++){
       for(j=0; j<q; j++){

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

	 time[i]--;
	 sumtime++;
	 if(time[i] == 0){
	   	anstime[num] = sumtime;
		strcpy(ansname[num],name[num]);
		num++;
		flag[i] = 1;
		flagcount++;

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

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