#include <stdio.h>
#include <stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=0, tail=0, n;

void enqueue(P x){
  if(head == (tail)%LEN){
    printf("1\n");
    exit(1);
  }
  Q[tail]=x;
  if(tail == LEN)tail = 0; 
  else tail++;

}

P dequeue(){
  P x;
  if(head == tail){
    printf("2");
    exit(2);
  }
  x = Q[head];
  if(head == LEN)head = 0;
  else head++;
  return x;

}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

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

  c = 0;
  while(c!=tail){
    if(Q[c].t-q <= 0){
      elaps += Q[c].t;
      printf("%s %d\n",Q[c].name,elaps);
      dequeue();
    }else{
      Q[c].t = Q[c].t - q;
      enqueue(Q[c]);
      dequeue();
      elaps += q;
    }
    if(c==LEN)c=0;
    else c++;
  }

  

  

  
  return 0;
}

