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

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

typedef struct strProcessQueue
{
  process value;
  struct strProcessQueue *next;
} processQueue;

processQueue *current;
processQueue *previous;
int qsize;

void printProcess(process);
void removeProcess();
int runProcess(int, int);

int main(void)
{
  int n, q, i, totalTime = 0;
  scanf("%d %d", &n, &q);
  qsize = n;
  current = (processQueue *) malloc(sizeof(processQueue));
  processQueue *first = current;
  for (i = 0; i < n; i++)
    {
      char name[11];
      int time;
      scanf("%s %d", name, &time);
      strcpy(current->value.name, name);
      current->value.time = time;
      if (i == n-1)
	  current->next = first;
      else
	current->next = (processQueue *) malloc(sizeof(processQueue));
      previous = current;
      current = current->next;
    }
  while (qsize > 0)
    totalTime = runProcess(q, totalTime);
  return 0;
}

void printProcess(process input)
{
  printf("%s %d\n", input.name, input.time);
}

void removeProcess()
{
  previous->next = current->next;
  free(current);
  current = previous->next;
  qsize--;
}

int runProcess(int q, int totalTime)
{
  if (current->value.time <= q)
    {
      totalTime += current->value.time;
      printf("%s %d\n", current->value.name, totalTime);
      removeProcess();
    }
  else
    {
      totalTime += q;
      current->value.time -= q;
      previous = current;
      current = current->next;
    }
  return totalTime;
}

