#include <stdio.h>
#include <string.h>
#define LEN 1000000

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

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

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

P deq()
{
  P x = Q[head];
  head = (head + 1) % LEN;

  return x;
}

int time(int x, int y){
  if(x < y){
    return x;
  }
  else{
    return y;
  }
}

int main(void)
{
  int elaps = 0, c, i, n, 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 = n + 1;

  while(head != tail){
    u = deq();
    c = time(q, u.t);
    u.t -= c;                         //残り時間
    elaps += c;                       //経過時間

    if(u.t > 0){
      enq(u);
    }
    else{
      printf("%s %d\n", u.name, elaps);
    }
  }
  return 0;
}

