#include <stdio.h>
#include <string.h>
#define N 100001

typedef struct
{
  char b[100];
  int c;
} A;

void enqueue(A);
A dequeue();

A a[N];
int n,head,tail;

int main()
{
  int i,q,total = 0;
  A d;

  scanf("%d%d",&n,&q);
  for(i = 0;i < n;i++)
    {
      if(scanf("%s%d",a[i].b,&a[i].c) == EOF) break;
    }
  head = 0;
  tail = n;
  while(head != tail)
    {
      d = dequeue();
      if(d.c > q)
	{
	  d.c = d.c - q;
	  total += q;
	  enqueue(d);
	} else
	{
	  total += d.c;
	  printf("%s %d\n",d.b,total);
	}
    }
  return 0;
}
void enqueue(A d)
{
  a[tail] = d;
  tail = (tail + 1) % N;
}
A dequeue()
{
  A d = a[head];
  head = (head + 1) % N;
  return d;
}
  
      
      
    
      

