#include<stdio.h>
#include<string.h>

typedef struct tt{
  char name[10];
  int t;
}A;
A Q[100000];
int head=0,tail,n;
void enqueue(A x){
  strcpy(Q[tail].name,x.name);
  Q[tail].t=x.t;
  tail++;
  if(tail==100000){
    tail=0;
  }
}
int main(){
  int elaps = 0;
  int i,q;
  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  tail=n;
  while(tail!=head){
    if(Q[head].t>q){
      elaps += q;
      Q[head].t -= q;
      enqueue(Q[head]);
    }else{
      elaps += Q[head].t;
      printf("%s %d\n",Q[head].name,elaps);
    }
    head++;
    if(head==100000){
      head = 0;
    }
  }
  return 0;
}