#include<stdio.h>
#define N 100000
 
typedef struct pp{
  char name[100];
  int t;
}Trump;
 
int h, sh, n, c=0, q;
Trump Q[N];

void mes(){
  Q[h].t = Q[h].t -q;
  Q[sh] = Q[h];
  if(sh > n+1) sh = 0;
  else sh++;
}
  
int main(){
  int i;
   
  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  h = 1;
  sh = n+1;
  i = 1;
  while(h != sh){
    if(Q[h].t > q){
      mes();
      c = c + q;
    }
    else{
      printf("%s %d\n",Q[h].name, Q[h].t+c);
      c = c + Q[h].t;
    }
    if(h > n+1) h = 0;
    else h++;
  }
  return 0;
}