#include <stdio.h>
#include <string.h>
#define N 100000
 
 
typedef struct
{
  int time;
  char name[10];
}P;
 
int head,tail,n;
int  min(int,int);
void enqueue(Pro);
P dequeue(void);
 
P Q[N];
 
int main()
{
  int q,i,c,e=0;
  P z;
 
  scanf("%d%d",&n,&q);
  
  for(i=1;i<=n;i++)
    {
      scanf("%s%d" ,Q[i].name,&Q[i].time);
    }
  
  head = 1;
  tail = n+1;
  while(head!=tail)
    {
      z = dequeue();
      c = min(q,z.time);
      z.time -= c;
      e += c;
      if(z.time > 0)
	{
	  enqueue(z);
	}
      else printf("%s %d\n",z.name,e);
    }
  return 0;
}
 
void enqueue(Pro x)
{
  Q[tail] = x;
  tail = (tail + 1)% N;
}

P dequeue()
{
  P x;  
  x = Q[head];
  head = (head + 1) % N;
    
  return x;  
}
 
int min(int v, int w)
{
  return v < w ? v:w;
}