#include  <stdio.h>
//#include
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
} P;

P Q[LEN+1];
int head, tail, n;


void enqueue(P x){
  Q[tail] = x;
  tail++;
  if (tail == LEN) tail = 0;
}

P dequeue(){
  int retdata = head;
  head++;
  if (head == LEN) head = 0;
  return (Q[retdata]);
}


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

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

  head = 1;
  tail = i;
  //\BD\E8\CD\FD\B3\AB\BB\CF
  
  while(1)
  {
    u = dequeue();
    u.t -= q;
    if (u.t > 0)
    {
      enqueue(u);
      elaps += q;
    }else{
      elaps += u.t + q;
      printf("%s %d\n", u.name, elaps);
    }

    if (tail == head) break;
  }

  
  return 0;
}


