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

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

int main(){
  int n, i, q, sum =0, last;
  P Q[LEN+1];
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  Q[n+1].name[0] = '\0';
  i = 1;
  last = n;
  while(1){
    if(Q[i].name[0] == '\0'){
      break;
    }
    if(Q[i].t > q){
      sum += q;
      strcpy(Q[last+1].name, Q[i].name);
      Q[last+1].t = Q[i].t - q;
      Q[last+2].name[0] = '\0';
      last++;
    } else {
      sum += Q[i].t;
      printf("%s %d\n", Q[i].name, sum);
    }
    i++;
  }   
  return 0;
}