#include <stdio.h>
#define Q_LEN 1000000
int queue[Q_LEN];
int head, tail;
void enque(int i) {
  if((tail+1)%Q_LEN == head) return;  
  queue[tail] = i;
  tail++;
  tail %= Q_LEN;
}
int deque() {
  int res;
  if(head == tail) return -1;
  res = queue[head];
  head++;
  head %= Q_LEN;
  return res;
}
int main() {
  int n, q, tim[100000], ela = 0;
  char name[100000][11];
  int i;
  scanf("%d %d", &n, &q);
  for(i = 0; i < n; i++) {
    scanf("%s %d", name[i], tim+i);
    enque(i);
  }
  while(head != tail) {
    i = deque();
    if(tim[i] <= q) {
      ela += tim[i];
      printf("%s %d\n", name[i], ela);
    } else {
      ela += q;
      tim[i] -= q;
      enque(i);
    }
  }
  return 0;
}