#include <stdio.h>
#define MAX_N 1010

typedef struct _Elm {
  char name[11];
  int time;
} Elm;



Elm que[MAX_N];
int head, tail;

void push(Elm value) {
  que[tail] = value;
  tail = (tail+1)%MAX_N;
}

Elm pop() {
  Elm value = que[head];
  head = (head+1)%MAX_N;
  return value;
}

int que_size() {
  return (MAX_N+tail-head)%MAX_N;
}

int main() {
  int n, q, i, cnt, time, t;
  Elm elm;
  scanf("%d %d", &n, &q);
  for(i = 0; i < n; ++i) {
    scanf(" %s %d", que[i].name, &(que[i].time));
  }

  head = 0;
  tail = n;

  time = 0;
  cnt = 0;

  while(que_size()) {
    elm = pop();
    t = q < elm.time ? q : elm.time;
    elm.time -= t;
    time += t;
    if(elm.time <= 0) {
      printf("%s %d\n", elm.name, time);
      ++cnt;
    } else {
      push(elm);
    }
  }
  return 0;

  for(i = 0, cnt = 0, time = 0; cnt < n; i = (i+1)%n) {
    if(que[i].time <= 0) continue;
    t = q < que[i].time ? q : que[i].time;
    que[i].time -= t;
    time += t;
    if(que[i].time <= 0) {
      printf("%s %d\n", que[i].name, time);
      ++cnt;
    }
  }
  return 0;
}