#include<stdio.h>
#define MAX 100000

typedef struct{
  char name[100];
  int time;
} roll;

void enqueue(roll);
roll dequeue(void);
int tail=0;
int head=0;


roll Q[MAX];

int main(void){
  int data;
  int q,i;
  int Queue=0;
  roll x;

  scanf("%d%d",&data,&q);
  
  for(i=0;i<data;i++){
    scanf("%s%d",x.name,&x.time);
    enqueue(x);
    
  }
  
  while(1){
    
    if(head == tail) break;
    
    if(Q[head].time > q){
      x = dequeue();
      x.time -= q;
      enqueue(x);
      Queue += q; 
    }
    else{
      x = dequeue();
      
      printf("%s %d\n",x.name,x.time+Queue);
      Queue += x.time;
    }
  }
  return 0;
}

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

roll dequeue(){
  
  roll x;

  x = Q[head];

  if(head+1 == MAX){
    head = 0;
  }
  
  else{ head++;  }
  return x;
}

