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

#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int n;
int head = 1;
int tail = 0;

void enqueue(P);
P dequeue(void);

int main()
{
  int i, q, c = 0;
  P u;

  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++)
    {
      scanf("%s", Q[i].name);
      scanf("%d", &Q[i].t);
    }

  tail = n+1;
  
  while(1)
    {
      u = dequeue();

      if(strcmp(u.name,"end") == 0)break;

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

void enqueue(P num)
{
  int next = (tail+1)%(LEN+1);

  if(next == head)
    {
      printf("Queue overflow!\n");
      exit(2);
    }
  Q[tail] = num;
  tail = next;
}

P dequeue(void)
{
  P val;

  if(head == tail)
    {
      strcpy(val.name,"end");
      return val;
    }
  val = Q[head];
  head = (head+1)%(LEN+1);
  return val;
}

