#include <stdio.h>

#define N 100000

typedef struct {
  char name[10];
  int time;
} Queue;

Queue Q[N];

int h=0, t, n;


void enqueue(Queue x){
  Q[t] = x;
  if(t + 1 == n){
    t = 0;
  }else{
    t++;
  }
}

Queue dequeue(void){
  Queue r;
  r = Q[h];
  if(h + 1 == n){
    h = 0;
  }else{
    h++;
  }
  return r;
}


int main(void){
  int i, q, elaps=0,c = 0;
  Queue data;
  scanf("%d%d", &n, &q);
  for(i=0; i<n; i++){
    scanf("%s%d", Q[i].name, &Q[i].time);
  }

  while(c != n){
    data = dequeue();
    if(data.time <=  q){
      elaps += data.time;
      c++;
      printf("%s %d\n", data.name, elaps);
    }else{
      elaps += q;
      data.time -= q;
      enqueue(data);
    }
  }
  return 0;
}

