#include <stdio.h>
#include <string.h>

main(){

  int i, j;
  int n,q;
  int process[1000];
  char name[1000][11];
  int tmp, elapsed;
  char tmps[11];
  int finishFlag;

  scanf("%d %d",&n,&q);
  for(i=0; i<n; i++){
    scanf("%s %d",name[i],&process[i]);
  }

  elapsed = 0;
  for(i=0; n>0; i++){
    finishFlag = 0;

    // process
    process[0] -= q;
    elapsed += q;
    if(process[0] <= 0){
      elapsed = elapsed+process[0];
      printf("%s %d\n",name[0],elapsed);
      finishFlag = 1;
    }

    // go to end of queue
    tmp = process[0];
    strcpy(tmps,name[0]);
    for(j=1; j<n; j++){
      process[j-1] = process[j];
      strcpy(name[j-1],name[j]);
    }
    process[n-1] = tmp;
    strcpy(name[n-1],tmps);

    if(finishFlag){
      n--;
    }

  }

}