#include<stdio.h>

#define nmax 100000

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

int main() {
  int i,j,x,n,t,sum=0;
  input in[nmax];

  scanf("%d%d",&n,&t);
  for(i = 0 ; i < n ; i++) {
    scanf("%s%d",&in[i].name,&in[i].time);
  }

  while(n > 0) {
    if(i == nmax)
      i = 0;
    else if(j == nmax)
      j = 0;
    if((x = in[j].time - t) > 0) {
      in[j].time = x;
      in[i] = in[j];
      sum += t;
      i++;
      j++;
    }
    else if((in[j].time - t) <= 0) {
      sum += in[j].time;
      printf("%s %d\n",in[j].name,sum);
      j++;
      n--;
    }
  }
  return 0;
}

