#include<stdio.h>
#include<string.h>
#define length 10000

typedef struct p{
  char name[10];
  int t;
}Data;

Data Q[length];
int f,e,n;

void enqueue(Data x)
{
  Q[e]=x;
  e=(e+1)%length;

}
Data dequeue()
{
  Data x=Q[f];
  f=(f+1)%length;
  return x;
}

int min(int a,int b){
  return a<b?a:b;
}

int main()
{
  int bre=0,c,i,q;
  Data u;
  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++)
    {
      scanf("%s",Q[i].name);
      scanf("%d",&Q[i].t);
    }
  f=1;
  e=n+1;
  while(f!=e)
    {
      u=dequeue();
      c=min(q,u.t);
      u.t=u.t-c;
      bre+=c;
      if(u.t>0)enqueue(u);
      else{
	printf("%s %d",u.name,bre);
	printf("\n");
      }
    }
  return 0;
}

