#include <stdio.h>
#include <string.h>
#define N 100000

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

int main(){
  int i, j, k = 0, n, q, sum = 0, key2;
  process a[N], key;

  scanf("%d%d", &n, &q);
  for(i = 0;i < n;i++){
    scanf("%s%d", a[i].name, &a[i].time);
  }
  while(1){
    if(a[n-1].time > 1000000 || n == 1) break;
    if(a[k].time > q){
      key.time = a[k].time - q;
      strcpy(key.name, a[k].name);
      for(i = k;i < n-1;i++){
	a[i] = a[i+1];
      }
      a[n-1] = key;
      key2 = sum + q;
    }
    else if(a[k].time < q){
      a[k].time += key2;
      sum = a[k].time + q;
      if(key2 == 0){
	a[k].time = a[k].time + a[k-1].time;
	q = a[k].time;
        if(k == n-1) break;
      } 
      k++;
      key2 = 0;
    }
  }  
  for(i = 0;i < n;i++){
    printf("%s %d\n", a[i].name, a[i].time);
  }
  return 0;
}