#include"stdio.h"
#include"stdlib.h"
#include"string.h"
struct que
{
  char name[10];
  int time;
  struct que *next;
};
typedef struct que* Que;
Que head;
Que fin;
Que getQue(Que back)
{
  back->next=(struct que*)malloc(sizeof(struct que));
  back->next->next=NULL;
  return back->next;
}
void push(char *name,int time)
{
  fin=getQue(fin);
  strcpy(fin->name,name);
  fin->time=time;
}
int deQue(int q)
{
  Que buf;
  static int time=0;
  if(head->next!=NULL)
    {
      if(head->next->time>q)
        {
          push(head->next->name,head->next->time - q);
          buf=head->next;
          head->next=head->next->next;
          time+=q;
          free(buf);
          return 1;
        }
      else
        {
          buf=head->next;
          head->next=head->next->next;
          time+=buf->time;
          printf("%s %d\n",buf->name,time);
          free(buf);
          return 1;
        }
    }
  else
    {
      return 0;
    }
}
int main()
{
  head=(struct que*)malloc(sizeof(struct que));
  fin=head;
  Que p;
  Que buf;
  int n,q;
  int time;
  char name[10];
  int i;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++)
    {
      scanf("%s%d",name,&time);
      push(name,time);
    }
  while(deQue(q));
  return 0;
}
