#include <stdio.h>
int head = 0,tail = 0;

typedef struct{
  int time;
  char job[20];
}Data;

Data a[100000];

Data DEQUEUE(void)
{
  if(head==100000)
    {
      head=0;
      return a[100000];
    }
  else
    {
      head++;
      return a[ head - 1 ];
    }
}

void ENQUEUE(Data j)
{
  if(tail==100000)
    {
      tail=0;
      a[tail]=j;
    }
  else
    {
      tail++;
      a[tail]=j;
    }
  return ;
}

int main(){
  int q,n,i,total = 0,count = 0;
  Data temp;
  Data c[100000];

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

  for(i=0;i<n;i++)
    {
      scanf("%s%d",a[i].job,&a[i].time);
    }

  tail = n - 1;
  while(1)
    {
      if(a[head].time <= q)
	{
	  temp = DEQUEUE();
	  total = total + temp.time;
	  temp.time = total;
	  c[count] = temp;
	  count++;
	}
      else
	{
	  total = total + q;
	  temp = DEQUEUE();
	  temp.time = temp.time - q;
	  ENQUEUE(temp);
	}
      if(head == tail+1) break;
    }
  for(i=0;i<n;i++)
    {
      printf("%s %d\n",c[i].job,c[i].time);
    }
  return 0;
}



