#include<stdio.h>
#define length 100000
int head,tail;

typedef struct {
  char name[100];
  int t;
}QU;

QU Q[length];

void enque(QU x){
  Q[tail]=x;//?¨?????????????????????£???????????????????°?????????\
  tail=(tail+1)%length;

}
QU deque(){
  QU x =Q[head];
  head=(head+1)%length;
  return x;
}

int main(){
  int n,q;
  int i,j,all_T=0,c;
  QU u;
  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s %d",Q[i].name,&Q[i].t);
  }
  head=1;
  tail=n+1;
  while(head!=tail){
    u=deque();
    if(u.t<q){all_T+=u.t;u.t=0;}
    else {u.t-=q; all_T+=q;}
    if(u.t>0)enque(u);
    else {
      printf("%s %d\n",u.name,all_T);
    }
  }
  return 0;
}