#include <stdio.h>
#define MAX 100000

typedef struct{
  char name[10];
  int time;
} Queue;

void initialize(void);
void enqueue(Queue);
Queue dequeue(void);
int isEmpty(void);
int isFull(void);

Queue queue[MAX];
int head;
int tail;

main(){
  int n, q, i, sum;
  Queue box;

  sum = 0;

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

  initialize();

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

  while( head != tail ){
    box = dequeue();
    if( box.time  >= q ){
      sum += q;
      box.time -= q;
      enqueue(box);
    }
    else{
      sum += box.time;
      printf("%s %d\n", box.name, sum);
    }
  }

  return 0;

}

void initialize(void){
  head = 0;
  tail = 0;
}

void enqueue(Queue x){

  if( isFull() == 1 ) printf("オーバーフロー\n");

  queue[tail] = x;

  if( tail + 1 == MAX ) tail = 0;
  else tail++;

}

Queue dequeue(void){
  Queue x;

  if( isEmpty() == 1 ) printf("アンダーフロー\n");

  x = queue[head];

  if( head + 1 == MAX ) head = 0;
  else head++;

  return x;

}

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

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