#include<stdio.h>

typedef struct
{
  char type[11];
  int num;
}q;

int main()
{
  q q[200000];
  int n;
  int p;
  int r = 0;
  int temp = 0;
  
  scanf("%d %d", &n, &p);
  int f = n-1;
  for(int i = 0 ; i < n; i++)
    {
      scanf("%s%d", q[i].type, &q[i].num);
    }
  while(r <= f)
    {
      if(q[r].num > p)
	{
	  temp += p;
	  q[r].num -=p;
	  q[++f] = q[r];
	}
      else
	{
	  temp += q[r].num;
	  printf("%s %d\n", q[r].type, temp);
	}
      r++;
    }
}

