#include <stdio.h>
#define N 100000

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

int main(void)
{
  queue Q[N];
  int n,q;
  int i;
  int total=0;
  int count=0;

  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++)
  {
    scanf("%s %d",Q[i].name,&Q[i].t);
  }
  i=0;
  while(1)
  {
      if(Q[i].t>0)
      {
        if(Q[i].t<=q)
        {
          total+=Q[i].t;
          Q[i].t=0;
          printf("%s %d\n",Q[i].name,total);
          count++;
          if(count==n) break;
        }
        else
        {
          total+=q;
          Q[i].t-=q;
        }
      }
      i++;
      if(i==n) i=0;
  }

  return 0;
}