#include <stdio.h>

#define LEN 100001

typedef struct {
  char name[11];
  int time;
} pro_t;

pro_t queue[LEN];
int head;
int tail;

void enqueue(pro_t Q, int n) {
  queue[tail] = Q;
  tail = (tail+1) % (n+1);
}

pro_t dequeue(int n) {
  pro_t ret;
  ret = queue[head];
  head = (head+1) % (n+1);
  return ret;
}

int min(int a, int b) {
  return (a < b) ? a : b;
}

int main() {
  int n;
  int q;
  int i;
  int elaps = 0;

  scanf("%d %d", &n, &q);

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

  while (head != tail) {
    pro_t v = dequeue(n);
    int tmp = min(v.time, q);
    elaps += tmp;
    v.time -= tmp;
    if (v.time > 0) {
      enqueue(v, n);
    }
    else {
      printf("%s %d\n", v.name, elaps);
    }
  }
  
  
  return 0;
}

