#include <stdio.h>
#include <stdlib.h>
#define max 11
typedef struct {
 int time;
 char name[max];
}process;

int main() {
 int i=0;
 int j;
 int n, q;
 int totaltime =0;
 scanf("%d %d", &n, &q);

 if (n > 100000 || q > 1000) return 0;

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


 for(;;){
  for (i = 0; i < n; i++) {
   process[i].time = process[i].time - q;

   if (process[i].time <= 0) {
    totaltime = (totaltime + process[i].time + q);
    printf("%s %d\n", process[i].name, totaltime);
    for (j = i; j < n - 1; j++) {
     process[j] = process[j + 1];
    }
    n--;
    i--;
   }

   else totaltime = totaltime + q;
  }

  if (n == 0) break;
 }

 return 0;
}



