#include <stdio.h>

typedef struct{

  char name[10];
  int time;
}Process;

Process queue[100000];
int eqp = 0;
int ebp = 0;
void enqueue(Process q){
  if(eqp == 100000)
   eqp = 0;

  queue[eqp] = q;
  eqp++;

}
Process dequeue(){
  if(ebp == 100000)
   ebp = 0;

  ebp += 1;
  return queue[ebp-1];
}


int main(){
int n, q, i, sum = 0;

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

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

 while(ebp != eqp){

  pro = dequeue();
   if(pro.time <= q){
     sum += pro.time;
     printf("%s %d\n", pro.name, sum);

   }
   else{
    sum += q;
    pro.time -= q;
    enqueue(pro);
   }
}




 return 0;
}