#include<stdio.h>
#define max 1000000
char name[max][12];
int time[max];

int count = 0;
int head = 0;
int tail = 0;
int sumtime = 0;

void enque(int t,char ar[]){
  
  if(tail==max)tail = 0;
  time[tail] = t;
  int i=0;
  while(ar[i]){
    name[tail][i] =ar[i];
    i++;
  } 
  tail++;
  count++;
}

int deque(){
  count--;
  if(head==max)head = 0;
  return time[head++];
  
}


char ar1[12];
int ti;

int main(){
  
  int n,q; scanf("%d %d",&n,&q);
  char sp;
  for(int i=0;i<n;i++){
    
    scanf("%s",ar1);
    scanf("%d",&ti);
    
    if(ti<=q){
       sumtime += ti;
      printf("%s %d\n",ar1,sumtime);
    }
    else{
      sumtime += q;
      enque(ti-q,ar1);
    }
    
  }
 
  
  while(count>0){
    int temp = deque();
    int index = head-1;
        if(temp<=q){
       sumtime += temp;
      printf("%s %d\n",name[index],sumtime);
    }
    else{
      sumtime += q;
      enque(temp-q,name[index]);
    }
  }
  
  
  
  
  return 0;
}
  

