#include <stdio.h>

#define LEN 100000

struct Process
{
  char name[11];
  int time;
};

int que[LEN];
int head = 0, tail = 0;

void enqueue(int a) {
  que[tail] = a;
  if (tail == LEN - 1)
    tail = 0;
  else
    tail++;
}

int dequeue() {
  int n = head;
  if (head == LEN - 1)
    head = 0;
  else
    head++;
  return que[n];
}

int main(void) {
  struct Process p[LEN];
  int n, q;
  int i;
  int time = 0;
  int deal;

  scanf("%d %d", &n, &q);
  for (i = 0; i < n; i++) {
    scanf("%s %d", p[i].name, &p[i].time);
    enqueue(i);
  }

  while(head != tail) {
    deal = dequeue();
    if (p[deal].time <= q) {
      time += p[deal].time;
      printf("%s %d\n", p[deal].name, time);
    }
    else {
      time += q;
      p[deal].time -= q;
      enqueue(deal);
    }
  }

  return 0;
}

