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

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

P Q[N];
  
int head,tail,n;


int min(int, int);


int main()
{
  int n,q,i,goukei=0;
  int sa;
  P nq;

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

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

  
  head=0;
  tail=n;
  
  while(head!=tail)
    {
      sa = min(q,Q[head].time);

      if(q<Q[head].time)
	{
	  goukei += q;
	  Q[tail].time = Q[head].time-q;
	  strcpy(Q[tail].name,Q[head].name);
	  tail++;
	}
      else
	{
	  goukei += Q[head].time;
	  printf("%s %d\n",Q[head].name,goukei);
	}
      head++;
      
    }

  return 0;
}
      

  
int min(int a, int b)
{
  if(a<b) return a;
  else return b;
}


