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


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

P Q[LEN+1];
int head,tail,num,q;

void enqueue(P);
P dequeue(void);


/*main??¢??°*/
int main(){
  int elaps = 0;
  int i, q;
  P proce;

  /*??\???*/
  scanf("%d %d", &num, &q);

  for ( i = 1; i <= num ; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  /*tail,head????????????*/
  head = 1;
  tail = num+1;

  while(head!=tail){

    proce=dequeue();
    if(proce.t > q){
      elaps += q;
      proce.t -= q;
    }

    else{
      elaps += proce.t;
      proce.t = 0;
    }

    if(proce.t == 0){
      printf("%s",proce.name);
      printf(" %d\n",elaps);
      num = num-1;
  }
    else {
      enqueue(proce);
    }
  }

  return 0;
}


/*?????\??????????´? x ?????????????????¢??° enqueue(x)*/
/*Q[tail] ??? x ?????£??\??????tail ??????????¢????????????????*/

void enqueue(P x){
  Q[tail] = x;
  tail++;
}

/*?????\??????????????????????´??????????????????¢??° dequeue( )*/
/*Q[head] ??????????????????head ??????????¢????????????????*/
P dequeue(){
  head++;
  return Q[head-1];
}