#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
int times[100000], que[100000];
char name[100000][15];

int main(void){
  int n, q, i, left, dec = 0, total = 0;
  
  scanf("%d %d",&n, &q);
  left = n;
  for(i=0;i<n;i++) {
    scanf("%s %d", name[i], &times[i]);
    que[i] = i;
  }
  while(left > 0){
    dec = 0;
    for(i=0;i<left;i++){    
      times[que[i]]-=q;
      total += q;    
   
      if(times[que[i]] <= 0){
	dec++;
	printf("%s ",name[que[i]]);
	total += times[que[i]];
	printf("%d\n",total);
      }
      else que[i-dec] = que[i];
    }
    left -= dec;
  }

  return 0;
}
