#include <stdio.h>
#include <stdlib.h>
#define N 100000
typedef struct P{
  char name[100];
  int time;
}P;
void enqueue(P);
P dequeue(void);
int head=0,tail=0,n;
P Q[N];

int main()
{
  int i,q,b,c,sum;
  P a;
  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++)
    {
      scanf("%s",Q[i].name);
      scanf("%d",&Q[i].time);
    }
  tail=n+1; head=1;

  while(head != tail)
    {
      a=dequeue();
      if(q<a.time) b=q;    
      else b=a.time;
      a.time -=b;
      sum+=b;
      if(a.time>0) enqueue(a);
      else printf("%s %d\n",a.name,sum);
    }	   

  return 0;
}

void enqueue(P x)
{
  Q[tail] =x;
  tail=(tail+1)%N;
}

P dequeue(void)
{
   P x=Q[head];
  head=(head+1)%N;
  return  x;
}



