#include <stdio.h>
#include <stdlib.h>
#define line 1000001
 struct data{
   char name[11];
   int time;
 };

struct data data[line];
void cal(int);
struct data deque();
void enqueue(struct data);
int head=0,tail;
  
int main(){
  int n,q,i,a,j;
 
  scanf("%d%d",&n,&q);

  tail=n;
  for(i=0;i<n;i++) scanf("%s%d",data[i].name,&data[i].time);

   
   while(head!=tail){
  //for(j=0;j<100;j++){
   
    cal(q);
    
    //   for(i=0;i<n;i++)printf("%s",data[head+i].name);
    //printf("\n");
    
  }


  return 0;
}

void cal(int q){

  static int time=0;
  struct data b;
  int r;

  b=deque(); 

  r=b.time-q;

  if(r>0){
    time+=q;
    b.time-=q;
    
    enqueue(b);
 }
  else {
    time+=b.time;
    printf("%s %d\n",b.name,time);
    
  }

}

struct data deque(){
  struct data a;
  a=data[head];
  head=(head+1)%line;
  return a;
}
void enqueue(struct data a){

  data[tail]=a;
  tail=(tail+1)%line;
  
}