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

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

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

void enqueue(P x){
  Q[tail] = x;
  tail++;
}

P dequeue(){
  head++;
  return Q[head-1];
}


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

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

  for(i = 1; n > 0; i++){
    time+=q;
    remain = Q[i].t - q;
    if(remain <= 0){
      u = dequeue();
      printf("%s %d\n", u.name, time = time+remain);
      n--;
    }else{
      Q[i].t = remain;
      enqueue(Q[i]);
      dequeue();
    }
    
  }
  return 0;
}

