#include <stdio.h>
#define len 100005
int head,tail;

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

P Q[len];
int head,tail;

void enquece(P x){
  Q[tail]= x;
  tail = (tail+1)%len;
}
P dequece(){
  P x = Q[head];
  head = (head+1)%len;
  return x;
}
int min(int a,int b){
  return a<b? a:b;
}

int main(void){
  int n,q;
  scanf("%d %d",&n,&q);
  head =1;
  tail= n+1;
  P pro;
  for (int i = 1; i < n; i++) {
    scanf("%s",Q[i].name );
    scanf("%d",&Q[i].time );
  }

int c;//処理時間
int elaps=0;// 経過時間
// For simulation
 while(head!=tail){
   pro = dequece();
  c= min(q,pro.time);
  elaps+=c;
  pro.time-=c;
  if (pro.time>0) {
    enquece(pro);
  }else{
    printf("%s %d\n",pro.name,elaps );
  }
}

return 0;


  }

