#include <stdio.h>
#define MAX 100000

typedef struct{
  char name[100];
  int time;
} queue;

void enq(queue);
queue deq(void);

int head=0, tail=0;
queue a[MAX];

main(){
  int n, m, i, sum=0;
  queue b;
  
  scanf("%d%d", &n, &m);
  for(i=0; i<n; i++){
	scanf("%s%d",b.name, &b.time);
	enq(b);
  }

  while(1){
	if(head==tail) break;
	if(a[head].time > m){
	  b = deq();
	  b.time -= m;
	  enq(b);
	  sum += m;
	}
	else{
	  b = deq();
	  printf("%s %d\n", b.name, b.time+sum);
	  sum += b.time;
	}
  }
  return 0;
}


void enq(queue p){
  a[tail] = p;
  if(tail+1 == MAX) tail = 0;
  else tail++;
}


queue deq(){
  queue x;
  x = a[head];
  
  if(head+1 == MAX) head = 0;
  else head++;
  return x;
}