#include<stdio.h>
#define LEN 1000

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

P Q[LEN+1];
int head = 0, tail = 0, n;

void enqueue (P x) {
  if(tail == n) tail = 1;
  else tail++;
  Q[tail] = x;
}

P dequeue() {
  if(head == n) head = 1;
  else head++;
  return Q[head];
}

int main () {
  int elaps = 0, count = 0;
  int i, q;
  P u;

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

  for(i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  while(count != n) {
    u = dequeue();
    if (u.t - q <= 0) {
      elaps += u.t;
      count++;
      printf("%s %d\n", u.name, elaps);
    }
    else {
      u.t -= q;
      elaps += q;
      enqueue(u);
    }
  }
  return 0;
}