#include <stdio.h>

#define N 100000

//function

struct process{
  char name[10];
  int ptime;
};
typedef struct process s_process;

void enque(s_process);
s_process deque(void);
void print_queue(void);
void print_result(void);

//global
s_process Q[N+1];
s_process R[N+1];
int length;
int head;
int tail;
int quan;
int total=0;

int main(){
  int i,count=0;
  int qtotal=0;

  s_process p;

  scanf("%d %d",&length,&quan);

  head = length/2;
  tail = length/2;

  for(i=0;i<length;i++){
    scanf("%s %d",p.name,&p.ptime);
    enque(p);
  }

  while(count != length){
      p = deque();
      if((p.ptime - quan) <= 0){
        qtotal += p.ptime;
        p.ptime = qtotal;
        R[count++] = p;
      }
      else{
        p.ptime -= quan;
        enque(p);
        qtotal += quan;
      }
  }

  print_result();
  return 0;
}

void enque(s_process p){

  Q[tail] = p;

  if(tail == length){
    tail = 0;
  }
  else tail++;
}

s_process deque(void){
  s_process p;
  p = Q[head];
  if(head == length)
    head=0;
  else head++;
  return p;
}

void print_queue(void){
  int i;

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

}

void print_result(void){
  int i;

  for(i=0;i<length;i++){
    printf("%s %d\n",R[i].name,R[i].ptime);
  }

}