
#include <stdio.h>
#define LEN 100005

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

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

void enqueue(P x);

P dequeue();


int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }
  tail=q;
  while(1){
    u=dequeue();
    if(u.t==0){
      c+=q;
    }
    else{
      u.t+=c;
      c+=u.t;
      printf("%s %d\n",u.name,u.t);
  }
    if(Q[1].t==0)break;
  }


  return 0;
}
