#include<stdio.h>
#include<string.h>
 
typedef struct p{
  char name[100];
  int time;
}Process;
 
Process Que[100000];
int head, tail, n;
 
void enqueue(Process x){
  Que[tail] = x;
  tail = (tail + 1)%100000;
}
 
Process dequeue(){
  Process x = Que[head];
  head = (head + 1)%100000;
  return x;
}
 
int min(int a, int b){ 
  return a < b ? a:b;
}
 
int main(void) {
  int i, n, q;
  scanf("%d %d\n", &n, &q);

  for (i=0; i<n;i++) {
      Process que;
      scanf("%s %d", que.name, &que.time);
      enqueue(que);
  }

  int e = 0;
  while (head != tail) {
      Process proc = dequeue();
      if (proc.time <= q) {
          e += proc.time;
          printf("%s %d\n", proc.name, e);
      } else {
          e += q;
          proc.time -= q;
          enqueue(proc);
      }
  }
  return 0;
}