#include<stdio.h>

#define Length 1000000
 
typedef struct{
  char name[20];
  int time;
}Quence;
 
Quence que[Length];

int head = 0, tail = 0;
 
void push(Quence);

Quence pop(void);

int size();


int main()
{
  int n, q;
  Quence Que;
  int i, j, x,clock = 0;
 
  scanf("%d %d",&n,&q);
  
  for(i = 0;i < n;i ++)
    {
      scanf("%s %d",Que.name,&Que.time);
      push(Que);
    }
 
  while(1)
    {
      Que = pop();
      if(Que.time <= q)
    {
      clock += Que.time;
      printf("%s %d\n",Que.name,clock);
    }
      else
    {
      Que.time -= q;
      clock += q;
      push(Que);
    }
 
      if(size()==0)break;
    }
 
  return 0;
}

void push(Quence q)
{
  que[head++] = q;
  
}
 
Quence pop(void)
{

  return que[++tail-1];
}
 
int size(void)
{
  return head-tail;
}