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

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

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

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

void enqueue(P x){
  Q[head] = x;
  head++;
}

P dequeue(){
  tail++;
  return Q[tail-1];
}

int main(){
  int sum_time = 0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

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

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