#include<stdio.h>
#define MAX 100005
int head,tail;
struct inf{
	char name[11];
	int time;
};
struct inf queue[MAX],what;
struct inf dequeue(){
	struct inf x;
	x=queue[head];
	head=(head+1)%MAX;
	return x;
}//取 
void enqueue(struct inf mid){
	queue[tail]=mid;
	tail=(tail+1)%MAX;
}//送 
int main(){
	int n,q,i,t=0;
	scanf("%d%d",&n,&q);
	head=1;
	tail=n+1;
	for(i=1;i<n+1;i++){
		scanf("%s%d",queue[i].name,&queue[i].time);
	}
	while(head!=tail){
		what=dequeue();
		if(what.time>q){
			what.time=what.time-q;
			enqueue(what);
			t=t+q;
		}
		else{
			t=t+what.time;
			printf("%s %d\n",what.name,t);
		}
	}//模拟 
	return 0;
} 
