#include <stdio.h>
#include <string.h>
#define N 1000 /* Q's length */

/* P's member */
typedef struct{
  char name[100];
  int t;
}P;

P Q[N]; /* make Q */
int head, tail, n;

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

P dequeue(){
  P x = Q[head];
  head++;
  return x;
}

/* small number return */
int mini(int x, int y){
  if(x < y) return x;
  else return y;
}

int main()
{
  /* time0 -> tortal time, time1 -> used time */
  int i, q, time0=0, time1;
  P s;

  scanf("%d%d", &n, &q);
  for(i = 1; i <= n; i++) scanf("%s%d", Q[i].name, &Q[i].t); /* add member in Q */
  head = 1;
  tail = n+1;

  while(head != tail){
    s = dequeue();
    time1 = mini(q, s.t); /* used time -> q or s.t */
    s.t -= time1;
    time0 += time1; /* add time */
    if(s.t > 0) enqueue(s);
    else printf("%s %d\n", s.name, time0);
  }

  return 0;
}