#include<stdio.h>
#include<string.h>
#define MAX 100000

typedef struct {
  int time;
  char name[10];
} P;

int n, head=0, tail;

int isEmpty(P []);
P dequeue(P []);
void enqueue(P [], P );

main()
{
  int i, q, time=0;
  P Q[MAX], x;

  scanf("%d %d", &n, &q);
  for(i=0; i<n; i++) scanf("%s %d", Q[i].name, &Q[i].time);

  tail = n;

  while(!isEmpty(Q))
    {
      if(q >= Q[head].time && Q[head].time != 0)
	{
	  time = time + Q[head].time;
	  printf("%s %d\n", Q[head].name, time);
	  if(head + 1 == MAX) head = 0;
	  else head++;
	}
      else
	{
	  Q[head].time -= q;
	  time += q;
	  x = dequeue(Q);
	  enqueue(Q, x);
	}
    }

  return 0;  
}

int isEmpty(P Q[])
{
  if(tail == head) return 1;
  else return 0;
}

P dequeue(P Q[])
{
  P x;
  x = Q[head];

  if(head + 1 == MAX) head = 0;
  else head++;

  return x;
}

void enqueue(P Q[], P x)
{
  Q[tail] = x;
  if(tail + 1 == MAX) tail = 0;
  else tail++;
}