#include <stdio.h>
#include <string.h>

typedef struct{
  char name[100];
  int t;
}Queue;
 
Queue Q[100000];
int i, head = 0, tail = 0;
 
void enqueue(Queue);
Queue dequeue(void);  
 
int main(){
  int p, q, count = 0, time = 0;
  Queue cell;
   
  scanf("%d %d",&i,&q);
   
  for (p = 1; p <= i; p++){
    scanf("%s",Q[p].name);
    scanf("%d",&Q[p].t);
  }
  
     printf("\n");

  
  while(count != i){
    cell = dequeue();
    if(cell.t - q <= 0){
      time += cell.t;
      cell.t = 0;
      count++;

 
      printf("%s %d",cell.name ,time);
      printf("\n");   
       
    } else if (cell.t > 0){
      time += q;    
      cell.t -= q;
      enqueue(cell);
    }
     
  }
   
  return 0;
  
}
   
 
void enqueue(Queue x){ 
 
  if(tail == i)   tail = 1;
   else {
    tail++;
  }
   
  Q[tail] = x;
}
   
 
Queue dequeue(){
  if(head == i)   head = 1;
   
  else {
    head++;
  }
  return Q[head];
}