#include <stdio.h>
#define N 100000

typedef struct{
  char name[100];
  int time;
}P;
 
int main(void){
 
  int head = 0, tail, i, n = 0, t = 0, q, x;
  P Q[N];
 
  scanf("%d %d", &n, &q);
 
  for(i = 0;i < n; i++) scanf("%s %d", Q[i].name, &Q[i].time);

  tail = n;   

  while(head != tail){
    x = Q[head].time - q;

    if(x <= 0){
      t += Q[head].time;
      printf("%s %d\n", Q[head].name, t);

      if(head == N - 1) head = 0;
      else head++;
    }

    else{
      Q[head].time = x;
      Q[tail] = Q[head];
      t += q;
      
      if(tail == N - 1) tail = 0;
      else tail++;
      
      if(head == N - 1) head = 0;
      else head++;
    }
  }

  return 0;
}