#include<stdio.h>

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

int main(){
  CUSTOMER queue[100000], p;
  int i, n, m, q, t = 0;

  scanf("%d%d",&n, &q);

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

  i = 0;

  while(1){
    m = n;

    if(queue[i].time > q){
      t += q;
      queue[i].time -= q;
    }

    else{
      t += queue[i].time;
      printf("%s %d\n",queue[i].name, t);
      n--;
    }

    if(n == 0) break;

    if(n == m) queue[i + n] = queue[i];
    else queue[i + m] = queue[i];

    i++;
  }

  return 0;
}