#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) 
{
  int h, i, n, q, s = 0, t = 1, time[100000];
  char name[100000][11];
  scanf("%d%d", &n, &q);
  for(i = 0; i < n; i++)
  {
    scanf("%s%d", name[i], &time[i]);
  }
  while(h != t)
  {
    if(time[h] <= q )
    {
      s += time[h];
      printf("%s %d\n", name[h], s);
    }
    else
    {
      s += q;
      strcpy(name[t], name[h]);
      time[t] = time[h] - q;
      if(t + 1 >= 100000 )
      {
        t = 0;
      }
      else
      {
        t++;
      }
    }
    if(h + 1 >= 100000)
    {
      h = 0;
    }
    else
    {
      h++;
    }
  }
  return 0;
}