#include<stdio.h>
int head=0,tail=0;

typedef struct{
  char name[11];
  int time;
}Q;
void inq(Q);
Q deq();
Q queue[100000];

int main(){
  int n,q,i,sumtime=0;
  Q queue,comp;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",queue.name,&queue.time);
    inq(queue);
  }
  i=0;
  while(i<n){
    comp=deq();
    if(comp.time>q){
      sumtime+=q;
      comp.time-=q;
      inq(comp);
    }else{
      sumtime+=comp.time;
      printf("%s %d\n",comp.name,sumtime);
      i++;
    }
  }
  return 0;
}

void inq(Q q){
  if(tail+1==100000)tail=0;
  tail++;
  queue[tail-1]=q;
}
Q deq(){
  if(head+1==100000)head=0;
  head++;
  return queue[head-1];
}

