#include<stdio.h>
#include<string.h>
#define LEN 100005

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

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

void enqueue(P x)
{
  int i;
  P tmp = Q[1];
  for(i = 1; i <= n-1; i++) 
    {
      Q[i] = Q[i+1];
    }
  Q[n] = tmp;
}

P dequeue()
{
  int i;
  P tmp = Q[1];
  for(i = 1; i <= n-1; i++) Q[i] = Q[i+1];
  return tmp;
}


int main()
{
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  while(n > 0)
    {
      if(Q[1].t > q)
	{
	  Q[1].t -= q;
	  u = Q[1];
	  elaps += q;
	  enqueue(u);
	}
      else
	{	  
	  u = dequeue();
	  elaps += u.t;
	  printf("%s %d\n",u.name,elaps);
	  n--;
	}	
    }
  return 0;
}