#include <stdio.h>
#include <string.h>

#define LENG 100000

typedef struct pp{

  char name[11];

  int time;

}P;

P Q[LENG];

int head = 0; 
int tail = 0;
int n;

void enqueue(P x){

  Q[tail] = x;

  if((tail + 1) == n)
    tail = 0;
  else
    tail++;
    
}

P dequeue(){

  P x;

  x = Q[head];

  if((head + 1) == n)
    head = 0;
  else
    head++;

  return x;

}


int main(){

  int i, q, alltime, count;
  P data;

  alltime = 0;
  count = 0;

  scanf("%d %d", &n, &q);

  for(i = 0; i < n; i++){

    scanf("%s %d", Q[i].name, &Q[i].time);

  }

  while(count != n){

    data = dequeue();

    if(data.time <= q){

      alltime += data.time;

      printf("%s %d\n", data.name, alltime);
      
      count++;

    }

    else{

      alltime += q;

      data.time -= q;

      enqueue(data);

    }

  }
  
  return 0;

}