#include<stdio.h>

#define N 100000

typedef struct process{
  char name[10];
  int tim;
}proceses;

proceses Q[N+1];
int length,quantum;
int head,tail;

void enqueue(proceses);
proceses dequeue(void);
void printqueue(void);

main(){
  int i;
  proceses p;
  int t_time=0;
  int count=0;
  
  scanf("%d %d",&length,&quantum);
  
  head = length/2;
  tail = length/2;
  
  for(i=0; i<length; i++){
    scanf("%s %d",p.name,&p.tim);
    enqueue(p);
  }

  while(count != length){
    
    p = dequeue();  
    if(p.tim > quantum){
      t_time += quantum;
      p.tim -= quantum;
      enqueue(p);
    }else{
      t_time += p.tim;
      printf("%s %d\n",p.name,t_time);     
      count++;
    }
    
  }
  
  return 0;
  
  
}

void enqueue(proceses p){
  
  Q[tail] = p;
  if(tail == length){
    tail = 0;
  }
  else 
    tail += 1;
}

proceses dequeue(){
  proceses x;  

  x = Q[head];
  if(head == length)
    head = 0;
  else 
    head++;
  
  return x;
}

void printqueue(void){
  int i;
  
  for(i=head; i!=tail; i++){
    if(i==length){
      printf("%s %d ",Q[i].name,Q[i].tim);
      i=0;
      printf("\n");
    }
    printf("%s %d ",Q[i].name,Q[i].tim);
    printf("\n");
  }

}