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

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

P Q[LEN+1];
int main(){
  int elaps = 0, c=0;
  int i, q,n;
  
  scanf("%d %d", &n, &q);

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    c+=Q[i].t;
  }
  i=0;
  while(elaps - c !=0){
    if(  Q[i].t!=0  ){
      if(   Q[i].t>q   ){
	Q[i].t-=q;
	elaps+=q;
      }
      else {
	elaps+=Q[i].t;
	printf("%s %d\n",Q[i].name,elaps);
	Q[i].t=0;
      }
    }
    i++;
    if(i>n)i=0;



}
  
  return 0;
}