#include <stdio.h>

typedef struct{
	char name[10];
	int t;
} process;
int n,q;
int i=0,j=0;
int timer=0;
int head=-1;
int tail=0;
int flag=0;
process x[1001];
void enqueue(process k){
if(tail==n){
tail=0;	
}
x[tail]=k;
tail++;
}

process dequeue(){

 head++;
 if(head==n){
 	head=0;
 }

return x[head];
}

int main(void){
	scanf("%d%d",&n, &q);
  for(i=0;i<n;i++){
  	scanf("%s%d",x[i].name,&x[i].t);
  	}
  while(flag!=n){
  	process k;
  	k= dequeue();
  	if(k.t<=q){
  		flag++;
  		timer+=k.t;
  		printf("%s %d\n",k.name , timer);
  	}else {
  		timer+=q;
  		k.t-=q;
  		enqueue(k);
  	}

  }
  
}