#include <stdio.h>

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

int main(){
  long long  n, q, i, j, sp, ep, stime = 0;
  process p[100000];
  scanf("%lld%lld", &n, &q);
  for(i = 0; i < n; ++i) scanf("%s%d", p[i].name, &p[i].time);

  sp = 0; ep = n - 1;
  while(sp <= ep){
    if(p[sp].time > q){
      stime += q;
      p[sp].time -= q;
      p[++ep] = p[sp];
    }
    else{
      stime += p[sp].time;
      printf("%s %lld\n", p[sp].name, stime);
    }
    sp++;
  }
  //  for(i = 0; i < n; ++i) printf("%s %d\n", p[i].name, p[i].time);
  return 0;
}