#include<stdio.h>
#include<cassert>
#include<string.h>
#define LEN 10000

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

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

void enqueue(P x){
  Q[tail] = x;
  if ( tail == LEN ) tail = 1;
  else tail++;
}

P dequeue(){
  P x = Q[head];
  if ( head == LEN ) head = 1;
  else head++;
  return x;
}
int min(int a, int b) {return a < b ? a : b;}
int max(int a, int b) {return a > b ? a : b;}

void trace(){
  int i;
  //  printf("(%d-%d)\n", head, tail);
  if ( head <= tail ){
    for ( i = head; i < tail; i++ ){
      printf("%s[%d] - ", Q[i].name, Q[i].t);
    }
    printf("\n");
  } else {
    for ( i = head; i <= LEN; i++ ){
      printf("%s[%d] - ", Q[i].name, Q[i].t);
    }
    for ( i = 1; i < tail; i++ ){
      printf("%s[%d] - ", Q[i].name, Q[i].t);
    }
    printf("\n");
  }
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  assert( 1 <= n && n <= 1000);
  assert( 1 <= q && q <= 1000);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    assert( strlen(Q[i].name) <= 10);
    scanf("%d", &Q[i].t);
    assert( 1 <= Q[i].t && Q[i].t <= 1000);
  }
  head = 1; tail = n+1;

  while( head != tail ){
    //    trace();
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if ( u.t > 0 ) enqueue(u);
    else {
      printf("%s %d\n",u.name, elaps);
    }
  }
  

  return 0;
}