#include <stdio.h>
#define MAX 100000

typedef struct _task {
  char name[11];
  int t;
} task;

int head, tail;

task tasks[MAX];

void enqueue(task t) {
  tasks[tail] = t;
  tail = (tail + 1) % MAX;
}

void dequeue() {
  head = (head + 1) % MAX;
}

int main() {
  int n, q, i, min, timer;
  head = tail = timer = 0;

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

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

  while(tail != head) {
    min = tasks[head].t > q ? q : tasks[head].t;
    tasks[head].t -= min;
    timer += min;

    if(tasks[head].t == 0) {
      printf("%s %d\n", tasks[head].name, timer);
    } else {
      enqueue(tasks[tail]);
    }
    dequeue();
  }

  return 0;
}

