#include <stdio.h>
#define MAX 100005

struct queue {
  char process[10];
  int time;
};

int head = 0, tail;
int n;
struct queue Q[MAX];

void enqueue(struct queue);
struct queue dequeue(void);
int isEmpty(void);
int isFull(void);

int main() {
  struct queue t;
  int i, q, runtime = 0, ex = 0;

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

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

  tail = n;

  /* Simulation */
  while(1){
    t = dequeue();
    if(t.time <= q) {
      runtime += t.time;
      printf("%s %d\n", t.process, runtime);
      ex++;
      if(ex == n) break;
    }else {
      runtime += q;
      t.time -= q;
      enqueue(t);
    }
  }

  return 0;

}

void enqueue(struct queue x){
  if(isFull() != 1){
    Q[tail] = x;

    if(tail + 1 == MAX) tail = 0;
    else tail++;
  }
  else printf("overflow...\n");
}

struct queue dequeue(void) {
  struct queue r;
  if(isEmpty() != 1){
    r = Q[head];
    if(head + 1 == MAX) head = 0;
    else head++;
    return r;
  }else {
    printf("underflow...\n");
    return;
  }
}

int isEmpty(void) {
  if (head == tail) return 1;
  else return 0;
}

int isFull(void) {
  if (head == ((tail + 1)%MAX)) return 1;
  else return 0;
}