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

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

P Que[LONG];
int head,tail,n;

P deque()
{
  P x =Que[head];
  head=(head+1)%LONG;
  return x;
}

void enqu(P x)
{
  Que[tail]=x;
  tail = (tail + 1)%LONG;
}

int min(int a,int b)
{
  return a<b ?a:b;
}

int main()
{
  int lap=0,c;
  int i,q;
  P u;
  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++)
    {
      scanf("%s",Que[i].name);
      scanf("%d",&Que[i].time);
    }
  head=1;tail = n+1;
  while(head!=tail)
    {
      u = deque();
      c = min(q,u.time);
      u.time-=c;
      lap +=c;
      if(u.time>0)enqu(u);
      else
	{
	  printf("%s %d\n",u.name,lap);
	}
    }
  return 0;
}