#include<stdio.h>
#include<string.h>

#define min(a,b) ((a)<(b)?(a):(b))

#define LEN 100000

typedef struct
{
  char name[10];
  int time;
} process;

process Q[LEN];
int head,tail,n;

void enqueue(process inf);
process dequeue();

int main(void)
{
  process inf;
  
  int time=0;
  int data;
  int i,q;

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

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

  head=1;
  tail=n+1;

  while(head!=tail)
    {
      inf=dequeue();
      data=min(q,inf.time);
      inf.time-=data;
      time+=data;
      if(inf.time>0)
	{
	  enqueue(inf);
	}
      else
	{
	  printf("%s %d\n",inf.name,time);
	}
    }
  return 0;
}

void enqueue(process inf)
{
  Q[tail]=inf;
  tail=(tail+1)%LEN;
}

process dequeue()
{
  process inf=Q[head];
  head=(head+1)%LEN;
  return inf;
}

