#include<stdio.h>

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

P Q[100010];
int head = 1, tail, n, j; 

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

P dequeue() {
    head = head+1;
    return Q[head-1];
}

int main () {
  int elaps = 0, c;
  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);
  }
  tail = n+1;

  for(i = 0; i < n + j; i++) {
    u = dequeue();
    if (u.t - q <= 0) {
      elaps += u.t;
      printf("%s %d\n", u.name, elaps);
    }

    else {
      u.t -= q;
      enqueue(u);
      elaps += q;
      j++;
    }
  }
 
  return 0;
}