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

#define MAX 100000
#define MAX_NAME 10

typedef struct {
  char name[MAX_NAME];
  int time;
  
}Process;

int head;
int tail;
Process Q[MAX];


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

int isEmpty()
{
  return head == tail;
}

int isFull()
{
  return head == (tail + 1) % MAX;
}

void enqueue(char *name, int time)
{
  if (isFull())
    exit(1);

  strcpy(Q[tail].name, name);
  Q[tail].time = time;

  tail = (tail + 1) % MAX;
    
}

Process dequeue()
{
  Process x;
  if (isEmpty())
    exit(1);

  x = Q[head];
  head = (head + 1) % MAX;
  
  return x;
}

int main(void)
{
  int n, q;
  char name[MAX_NAME];
  int time;
  Process p;
  
  scanf("%d %d", &n, &q);
  while (scanf("%s %d", name, &time) != EOF) {
    enqueue(name, time);
  }

  int sim_time = 0;
  while (!isEmpty()) {
    sim_time += q;
    p = dequeue();

    p.time -= q;
    if (p.time <= 0) {
      sim_time += p.time;
      printf("%s %d\n", p.name, sim_time);
    }
    else
      enqueue(p.name, p.time);
  }
  return 0;
}

