#include<stdio.h>
#include<string.h>

int head=0,tail=0,n;
typedef struct{
	char pr[10];
	int time;
}pro;
pro que[100001],test;
void enqu(pro);
pro dequ(void);

int main(){
	pro p;
	int i,a,b,q,sum=0;
	test.time=0;
	scanf("%d%d",&n,&q);
	for(i=0;i<n;i++){
		scanf("%s%d",p.pr,&p.time);
		enqu(p);
	}
	while(1){
		p=dequ();
		if(p.time==test.time)break;
		p.time=p.time-q;
		if(p.time<=0){
			sum+=q+p.time;
			printf("%s %d\n",p.pr,sum);
		}else{
			sum+=q;
			enqu(p);
		}
	}
	return 0;
}

void enqu(pro a){
	if(tail==n+1)tail=0;
	strcpy(que[tail].pr,a.pr);
	que[tail].time=a.time;
	tail++;
}
pro dequ(){
	if(head==tail){
		test.time=-1;
		return test;
	}
	if(head==n+1)head=0;
	head++;
	return que[head-1];
}

