#include <stdio.h>
#include <string.h>
#define MAX 200000
typedef struct a{
  char name[100];
  int time;
}DATA;
void enqueue(DATA);
DATA dequeue(void);
int isEmpty(void);
int head=0,tail=0,n;
DATA Q[MAX+1];
int main()
{
  int total=0,q,i;
  scanf("%d%d",&n,&q);
  tail=n;
  for(i=0;i<=n;i++)
    {
      scanf("%s%d",Q[i].name,&Q[i].time);
    }
  for(i=0;isEmpty()!=1;i++)
    {
      if(Q[i].time>q)
	{
	  Q[i].time=Q[i].time-q;
	  enqueue(Q[i]);
	  dequeue();
	  total=total+q;
	}
      else if(Q[i].time<=q)
	{
	  total=total+Q[i].time;
	  printf("%s",Q[i].name);
	  printf(" ");
	  printf("%d",total);
	  printf("\n");
	  dequeue(); 
	}
    }
  return 0;
}
void enqueue(DATA x)
{
  Q[tail].time=x.time;
  strcpy(Q[tail].name,x.name);
  if(tail+1==MAX)
    tail=0;
  else tail++;
}
DATA dequeue(void)
{
  DATA x;
  x=Q[head];
  if(head+1==MAX)
    head=0;
  else head++;
  return x;
}
int isEmpty(void)
{
  int flag=0;
  if(head==tail)
    {
      flag=1;
      return flag;
    }
  return flag;
}

