#include<stdio.h>

#define MAX 100000

typedef struct
{
  char name[11];
  int time;
  int sum;
} ps;

int isEmpty();
int isFull();
void enqueue(ps);
ps dequeue();

int head = 0, tail = 0;
ps que[MAX];

int main()
{
  int i, n, q, st=0;
  ps x, a[MAX];
  x.sum=0;
  
  scanf("%d%d", &n, &q);
  for(i=0; i<n; i++)
    {
      scanf("%s%d", x.name, &x.time);
      enqueue(x);
    }

  i=0;
  while(!isEmpty())
    {
      x = dequeue();
      if(x.time > q)
	{
	  st += q;
	  x.time -= q;
	  enqueue(x);
	}
      else
	{
	  x.sum += x.time+st;
	  a[i] = x;
	  i++;
	  st += x.time;
	}
    }
  
  for(i=0; i<n; i++)
    {
      printf("%s %d\n", a[i].name, a[i].sum);
    }
  
  return 0;
}

int isEmpty()
{
  return head == tail;
}
int isFull()
{
  return head == (tail+1)%MAX;
}
void enqueue(ps x)
{
  if(isFull())
    {
      printf("OVF\n");
    }
  que[tail] = x;
  if(tail+1 == MAX)
    {
      tail = 0;
    }
  else
    {
      tail++;
    }
} 
ps dequeue()
{
  if(isEmpty())
    {
      printf("UNF\n");
    }
  ps x = que[head];
  if(head+1 == MAX)
    {
      head = 0;
    }
  else
    {
      head++;
    }
  return x;
}