#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int q, current_time;

struct _task {
  struct _task *next;
  struct _task *prev;
  char name[11];
  int time, done_time;
};
typedef struct _task task;

task task_head = { &task_head, &task_head, "", 0 };
task *current_task;

task done_task_head = { &done_task_head, &done_task_head, "", 0 }; // 処理済みのタスクの先頭

void add_task(char *name, int time) {
  task *new;
  new = (task *)malloc(sizeof(task));

  strcpy(new->name, name);
  new->time = time;
  new->prev = task_head.prev;
  new->next = &task_head;
  task_head.prev->next = new;
  task_head.prev = new;
}

void done_task(task *done_task, int time) {
  done_task->prev->next = done_task->next;
  done_task->next->prev = done_task->prev;

  done_task_head.prev->next = done_task;
  done_task->prev = done_task_head.prev;
  done_task_head.prev = done_task;
  done_task->next = &done_task_head;

  done_task->done_time = time;
}

void process_task() {
  if(q < current_task->time) {
    current_task->time -= q;
    current_time += q;

    current_task = current_task->next;
  } else {
    current_time += current_task->time;
    current_task->time = 0;

    current_task = current_task->next;
    done_task(current_task->prev, current_time);
  }
}

void show_list() {
  task *x;
  x = done_task_head.next;

  while(x != &done_task_head) {
    printf("%s %d\n", x->name, x->done_time);
    x = x->next;
  }
}

int main(void) {
  int n, i, time;
  char name[11];

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

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

  current_task = task_head.next;
  while(task_head.next != &task_head) {
    if(current_task == &task_head)
      current_task = current_task->next;

    process_task();
  }

  show_list();

  return 0;
}

