#include <stdio.h>
#include <stdlib.h>

#define LEN 100005

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

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

void enqueue(P);
P dequeue(void);

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

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

  while(head != tail){
     u = dequeue();
    if(u.t > q){
      u.t -= q;
      elaps += q;
      enqueue(u);      
    }else if(u.t <= q){
      elaps += u.t;
      printf("%s %d\n",u.name,elaps);
      /* if(head + 1 == LEN) head = 0; */
      /* else head++; */
    }
    //if(u.t == -1) exit(1);
  }
	
  return 0;
}

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

P dequeue(void){
  P x;
  
  x = Q[head];
  if(head + 1 == LEN){
    head = 0;
  }else head++;
  return x;
}
		
  

