#include <stdio.h>
#include <string.h>
#define LEN 1000005
#define MAX 1000


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


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


void initialize();
//?????\?????????????¨????
int Empty();
//?????\?????????????????????
int isFull();
//?????\?????????????????????
void enqueue(P);
//tail???????????´??????x?????????, MAX??\???????????£??????????????´??????tail???0??¨???????????°
P dequeue();
//head??????????????\???????????????????´?????????°x????????????????¨??????????head???1?¢????????????????x?????????


int main(){

  int elaps=0,c;
  int i,q;
  P u;

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

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

  for ( i = 1; tail != head; i++){



    if( Q[i].t > q){  
      Q[i].t = Q[i].t - q;
      elaps += q;
      Q[i] = dequeue();
      enqueue(Q[i]);
    }

    else{
     elaps += Q[i].t;
     printf("%s %d\n",Q[i].name,elaps);
     //u = dequeue();
     head++;
   }

 }
 return 0;
}


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


void enqueue(P x){
  tail++;
  Q[tail] = x;
  //if(tail + 1 == MAX) tail = 0;
  //else

}


P dequeue(){

  P x;
  head++;
  x = Q[head];
  /*if(head + 1 == MAX) head = 0;
  else head++;*/
  return x;
}