#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUF_SIZE 20

struct process {
  char name[12];
  int time;
};

#define min(a, b) ((a) > (b) ? (b) : (a))

#define QUEUE_SIZE 100001
static int queue[QUEUE_SIZE];
static int start = 0;
static int end = 0;

void enqueue(int idx) {
  end = (end+1)%QUEUE_SIZE;
  queue[end] = idx;
}

int dequeue(void) {
  start = (start+1)%QUEUE_SIZE;
  return queue[start];
}

int is_empty(void) {
  return start == end;
}

int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int num, quantum;
  sscanf(line, "%d %d", &num, &quantum);
  struct process *ps = malloc(sizeof(struct process)*num);

  int i, j;
  for(i = 0; i < num; i++) {
    if(!fgets(line, BUF_SIZE, fp)) return 0;
    sscanf(line, "%s %d", ps[i].name, &ps[i].time);
    enqueue(i);
  }

  int sum = 0;
  while(!is_empty()) {
    int idx = dequeue();
    struct process *proc = &ps[idx];
    int consume = min(quantum, proc->time);
    proc->time = proc->time - consume;
    sum += consume;
    if(!proc->time) {
      printf("%s %d\n", proc->name, sum);
    } else {
      enqueue(idx);
    }
  }
  return 0;
}
