#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int time;
}P;

P Q[LEN+1];
int head=0,tail,tk=0;
void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}
P dequeue(){
  P x=Q[head];
  head=(head+1)%LEN;
  return x;
}

  
int main(){
  int n,q,i;
  P u;
  scanf("%d%d",&n,&q);
  for(i=0;i < n;i++){
    scanf("%s%d",Q[i].name,&Q[i].time);
  }
  tail=n;
  while(head != tail){
    u=dequeue();
    if(u.time > q){
      tk+=q;
      u.time=u.time-q;
      enqueue(u);
    }
    else{
      tk+=u.time;
      printf("%s %d\n",u.name,tk);
    }
  }
  return 0;
}

