#include <stdio.h>
#include <stdlib.h>
#define N 100000
#define L 10

// define the structure
typedef struct Process {
  char name[10];
  int time;
} Processor;

int main() {
  int i, n, q;
  int cnt = 0;
  int qhead = 0, qtail;
  Processor pr[N];

  // input each process
  scanf("%d %d", &n, &q);
  for(i = 0; i < n; i++) {
    if(scanf("%s %d", pr[i].name, &pr[i].time) == EOF) break;
  }

  qtail = i;
  // simulate
  while(1) {
    if(qtail == n - 1) {
      qtail = 0;
    }
    if(qhead == n - 1) {
      qhead = 0;
    }
    
    if (pr[qhead].time <= q) {
      // complete the process
      cnt += pr[qhead].time;
      printf("%s %d\n", pr[qhead].name, cnt);
      // dequeue
      qhead++;
    }
    else {
      pr[qhead].time -= q;
      cnt += q;   
      // engueue
      pr[qtail++] = pr[qhead];
      // dequeue
      qhead++;
    }
    // all complete
    if(qhead == qtail) break;
  }
  
  return 0;
}

