#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX 131072
#define NAME 16

typedef struct {
  char name[NAME];
  unsigned int time;
} pros_t;

long head, tail;
pros_t x, Q[MAX];

void initialize(){
  for (head = 0; head < MAX; head++){
    memset(Q[head].name, '\0', NAME);
    Q[head].time = 0;
  }
  head = tail = 0;
}

int isEmpty(){
  return head == tail;
}

int isFull(){
  return head == (tail + 1) % MAX;
}

int enqueue(pros_t x){
  if (isFull())
    puts("over flow");
  Q[tail] = x;
  if (tail + 1 == MAX)
    tail = 0;
  else
    tail++;
  return 0;
}

pros_t dequeue(){
  if (isEmpty())
    puts("under flow");
  x = Q[head];
  if (head + 1 == MAX)
    head = 0;
  else
    head++;
  return x;
}
  
int main(void){
  long n, i, finish = 0;
  int q;
  pros_t tmp;

  initialize();
  scanf("%ld", &n);
  scanf("%d", &q);
  for(i = 0; i < n; i++) {
    scanf("%s", tmp.name);
    scanf("%d", &tmp.time);
    enqueue(tmp);
  }
  while(head != tail){
    tmp = dequeue();
    if (tmp.time <= q) {
      finish += tmp.time;
      printf("%s %ld\n", tmp.name, finish);
    }
    else {
      finish += q;
      tmp.time -= q;
      enqueue(tmp);
    }
  }
  return 0;
}