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

#define QSIZE 100000

struct _q{
  char n[11];
  int  t;
} q[QSIZE];
int qs=0,qe=0;

void enqueue(struct _q *ptq){
  q[qe].t=ptq->t;
  strncpy(q[qe].n,ptq->n,10);
  qe++; if (qe==QSIZE) qe=0;
  return;
}

struct _q *dequeue(){
  int qc=qs;
  if (qs==qe) return NULL;
  qs++; if (qs==QSIZE) qs=0;
  return &q[qc];
}

int main(){
  int N,Q,t=0;
  struct _q tq, *ptq;
  scanf("%d %d\n",&N,&Q);
  while(scanf("%s %d\n",tq.n,&tq.t) != EOF){
    if(tq.t>Q){
      t+=Q; tq.t-=Q;
      enqueue(&tq);
    }
    else{
      t+=tq.t;
      printf("%s %d\n",tq.n, t);
    }
  }

  ptq = &tq;
  while ((ptq=dequeue()) != NULL) {
    if(ptq->t>Q){
      t+=Q;
      ptq->t-=Q;
      enqueue(ptq);
    }
    else{
      t+=ptq->t;
      printf("%s %d\n",ptq->n, t);
    }
  }
  return 0;
}