#include <stdio.h>

#define QUEUE_SIZE 100000
#define NAME_LEN 10

typedef struct {
  char name[NAME_LEN];
  int time;
}process;

process Queue[QUEUE_SIZE];
int head, tail;

void print_process(process p)
{
  printf("%s %d\n", p.name, p.time);
  return;
}

void initialize(void)
{
  head = 0;
  tail = 0;
  return ;
}

process pop(void)
{
  process p;
  p = Queue[head];
  head = (head + 1) % QUEUE_SIZE;
  return p;
}

void append(process p)
{
  memcpy((void *)Queue[tail].name, (void *)p.name, NAME_LEN);
  Queue[tail].time = p.time;

  tail = (tail + 1) % QUEUE_SIZE;
  return;
}

int is_empty(void)
{
  return (head == tail);
}

int main(void)
{
  int n, q;
  int i;
  int time = 0;

  initialize();
  scanf("%6d %4d", &n, &q);

  for(i = 0; i < n; i++){
    process p;
    scanf("%10s %5d", p.name, &(p.time));
    append(p);
  }

  /* printf("%d\n", i); */

  while(!is_empty()){
    process p;
    int remain;
    p = pop();
    remain = p.time;
    p.time -= q;
    if(p.time <= 0){
      time += remain;
      printf("%s %d\n", p.name, time);
    }else{
      time += q;
      append(p);
    }
  }

  return 0;
}