#include <stdio.h>
#define LEN 100000

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

Process Q[LEN];
int n, q, head = 0, tail = 0;

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

Process dequeue(){
  Process x = Q[head];
  head = (head + 1)%LEN;
  return x;
}

int main(void)
{
  int i, j, count, time = 0;
  Process x;
  scanf("%d %d", &n, &q);

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

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