#include<stdio.h>
#include<string.h>
#define MAX 100000

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

main()
{
  int q, i, j, k=0, n, N, keikatime=0;
  P Q[MAX], Q_re[MAX];

  scanf("%d %d", &n, &q);
  for(i=0; i<n; i++)
    {
      scanf("%s %d", Q[i].name, &Q[i].time);
    }
  printf("\n");

  N = n;
  i=0;
  while(1)
    {
      Q[n].time = Q[0].time - q;
      
      if(Q[n].time <= 0)
	{
	  keikatime = keikatime + Q[0].time;
	  
	  Q_re[k].time = keikatime;
	  for(j=0; j<k; j++)
	    {
	      if(strcmp(Q[i].name, Q_re[j].name)==0)
		{
		  i = i+1;
	 
		}
	    }
 
	  strcpy(Q_re[k].name, Q[i].name);
	  k++;
	  
	  for(j=0; j<n; j++)
	    {
	      Q[j].time = Q[j+1].time;
	    }
	  n = n - 1;
	}
      else
	{
	  for(j=0; j<n; j++)
	    {
	      Q[j].time = Q[j+1].time;
	    }
	  keikatime += q;
	}

      i++;
      if(i == 5)
	{
	  i = 0;
	}
      if(n == 0)
	{
	  break;
	}
    }

  for(i=0; i<N; i++)
    {
      printf("%s %d\n", Q_re[i].name, Q_re[i].time);
    }

  return 0;
}