#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
#define LEN 10

typedef struct{
  char name[LEN];
  int time;
}process;

void enq(process);
process deq();
int isFull(void);
int isEmpty(void);

process queue[MAX];
int head = 0;
int tail = 0;

int main(){
  process in[MAX];
  int n, q, ans = 0;
  int i;

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

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

  /*for(i=0;i<n;i++){
    printf("%s %d\n", queue[i].name, queue[i].time);
    }*/

  while(isEmpty() != 1){
    if(queue[head].time <= q){
      ans += queue[head].time;
      printf("%s %d\n", queue[head].name, ans);
      deq();
    }
    else{
      queue[head].time -= q;
      ans += q;
      enq(deq());
    }
  }
    
  return 0;
}

void enq(process x){
  if(isFull() == 1){
    printf("queue overflow!\n");
    exit(1);
  }
  queue[tail] = x;
  tail++;
  if(tail == MAX) tail = 0;
}

process deq(){
  if(isEmpty() == 1){
    printf("queue underflow!\n");
    exit(1);
  }
  head++;
  if(head == MAX){
    head = 0;
    return queue[MAX-1];
  }
  else return queue[head-1];
}

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

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

