#include <stdio.h>

typedef struct{
  char name[10];
  int t;
} Process;

int main(int argc, char const *argv[]) {

  int num,times,i;
  Process Q[200000];
  int count = 0, sum = 0;

  scanf("%d%d",&num,&times);

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

  for( i = 0 ; i < num ; i++ ){

    Q[i].t -= times;

    if( Q[i].t <= 0 ){
      sum += Q[i].t+times;
      printf("%s %d\n",Q[i].s,sum);
    }else{
      Q[num] = Q[i];
      sum += times;
      num++;
    }

  }

  return 0;
}