#include <stdio.h>
#define N 100000

typedef struct{
  int time;
  char name[10];
} DM;

int main(){
  DM it[N];
  int q,n,i,j,count=0,l=0;
  int head,tail;
  
  scanf("%d %d",&n, &q);
  
  for(i=0 ; i<n ; i++){
    scanf("%s %d",it[i].name, &it[i].time);
  }
  
  head =0;
  tail = n;
  while(head!=tail){
    for(j=head ; j<tail ; j++){
      for(i=0 ; i<q ; i++){
	if(it[j].time>0){
	  it[j].time--;
	  count++;
	}
	if(it[j].time==0){
	  printf("%s %d\n",it[j].name,count);
	  break;
	}
      }
      if(it[j].time!=0){
	l = tail;
	tail++;
	it[l] = it[j];
      }
      head++;
    }
  }
  return 0;
}

