#include<stdio.h>
#include<string.h>
typedef struct proces{
  char name[10];
  int count;
  int time;
  }def;

int head,n,tail;
def c[100000];


void enq(def s){
  c[tail]=s;
  
  tail=(tail+1)%100000;

}


def deq(){
  def sd=c[head];
  head=(head+1)%100000;
  
  return sd;
}


int min(int k,int l){
  if(k>l) return l;
  else return k;
}


int main(){
  int tasu,i,q,b,sum=0;
  def type;
  scanf("%d %d",&b,&q);
  for(i=1;i<=b;i++){
    scanf("%s",c[i].name);
    scanf("%d",&c[i].time);
    c[i].count=1;
  }
  head=1;
  tail=b+1;
  while(tail != head){
    type=deq();
    tasu=min(q,type.time);
    type.time=type.time-tasu;
    sum=sum+tasu;
    if(type.time>0){
      enq(type);
    }
    else if(type.count==1){
      
      printf("%s %d\n",type.name,sum);
      type.count=0;
    }
    
  }
  return 0;
}

