#include <stdio.h>
#include <string.h>
#define N 10000

int main(void) {
  int n, q, time[N];
  int i, sum = 0;
  int head = 0, tail = 0;
  char name[n][11];
  scanf("%d %d", &n, &q);
  for (i = 0; i < n; i ++) {
    scanf("%s %d", name[i], &time[i]);
    tail ++;
  }
  if (tail == 1) {
    printf("%s %d\n", name[head], time[head]);
    return 0;
  }
  while(head != tail) {
    if (time[head] > q) {
      sum += q;
      time[head] -= q;
      strcpy(name[tail], name[head]);
      time[tail] = time[head];
      tail ++;
      if (tail >= N) tail = 0;
    }
    else {
      sum += time[head];
      printf("%s %d\n", name[head], sum);
    }
    head ++;
    if(head >= N) head = 0;
  }
  return 0;
}