#include <stdio.h>
#define M 100000
typedef struct {
  char name[10];
  int t;
} QUEUE;

QUEUE que[M];
int front, rear;

void Enqueue(QUEUE x) {
  if (rear == M) rear = 0;
  que[rear] = x;
  rear++;
}

QUEUE Dequeue(void) {
  if (M == front) front = 0;
  return que[front++];
}

int main(int argc, char const *argv[]) {
  int i, n, q, exet = 0;
  QUEUE queue;
  scanf("%d %d", &n, &q);
  for (i = 0; i < n; i++) {
    scanf("%s %d", queue.name, &queue.t);
    Enqueue(queue);
  }

  while (n != 0) {
    queue = Dequeue();
    if (queue.t > q) {
      queue.t = queue.t - q;
      exet = exet + q;
      Enqueue(queue);
    } else {
      exet = exet + queue.t;
      printf("%s %d\n", queue.name, exet);
      n--;
    }
  }
  return 0;
}