#include <stdio.h>

#define LEN 100000

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

P queue[LEN];

int head = 0;
int tail;

void enqueue(P);
P dequeue(void);

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

  for(i = 0; i < n; i++) {
    scanf("%s%d",x.name,&x.t);
    enqueue(x);
  }
  

  ncount = n;
  while(1) {
    x = dequeue();
    if(x.t > q) {
      elaps+= q;
      x.t -= q;
      enqueue(x);
    }
    else {
      elaps += x.t;
      printf("%s %d\n",x.name,elaps);
      ncount--;
      if(ncount == 0) break;
    }
  }
  
  return 0;
}

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

P dequeue(void)
{
  P x;

  x = queue[head];
  head = (head+1) % LEN;
  return x;
}



