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


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

void enqueue(P);
P dequeue(void);
void initialize(void);
int isEmpty(void);
int isFull(void);

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

int main(){
  int elaps = 0, c;
  int i, q; //q:???????????????
  P u;
  scanf("%d %d", &n, &q);

  initialize();

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = n+1;

  while(1){
    if(isEmpty()) break;

    u=dequeue();

    if(u.t > q ){
      elaps +=q;
      u.t -= q;
      enqueue(u); 
    }
    else {
      elaps +=u.t;
      printf("%s %d\n",u.name,elaps);
    }

  }

  return 0;
}


void initialize(void){
  head = tail = 0;
}

int isEmpty(void){
  return head == tail;
}

int isFull(void){
  return head == (tail + 1) % LEN;
}

void enqueue(P x){ /* ?????\??????????°????????´? x ????????????????????? */
  if(isFull()) fprintf(stderr,"overflow\n");
  Q[tail] = x;
  if (tail + 1 == LEN) tail = 0;
  else tail++;
}

P dequeue(void){ /* ?????\??????????????????????´????????????????????????? */
  P x;
  if(isEmpty()) fprintf(stderr,"underflow\n");
  x = Q[head];
  if (head + 1 == LEN) head = 0;
  else head++;
  return x;
}