#include <stdio.h>
#define len 1000001

typedef struct process {
  char name[11];
  int time;
} P;

P origin[len];
int head, tail;

void push(P x) {
  origin[tail] = x;
  tail = (tail + 1) % len;
}

P pop() {
  P x = origin[head];
  head = (head + 1) % len;
  return x;
}

int ismin(int a, int b) {
  return a < b ? a : b;
}

int main() {
  int sum = 0, ptime;
  int n, q;
  int i;
  P quene;

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

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

  head = 0;
  tail = n;

  while (head != tail) {
    quene = pop();
    ptime = ismin(q, quene.time);
    quene.time -= ptime;
    sum += ptime;
    if (quene.time > 0) {
      push(quene);
    } else {
      printf("%s %d\n", quene.name, sum);
    }
  }

  return 0;
}

