#include <stdio.h>

struct pro {
		char proname[8];
		int protime;
		struct pro *next;
		};
	typedef struct pro _Pro;
	
int main(void){
	int n,q,i;
	char *proNum[100000];
	int cnt = 0;
	int tcnt = 0;
	_Pro *p;
	_Pro head = {"",0,p};
	
	scanf("%d %d",&n,&q);
	
	for( i = 0; i < n-1; i++){
		
		scanf("%s %d",p->proname,p->protime);
		p->next = p + 1;
		p = p->next;
	};
	
	scanf("%s %d",p->protime, p->proname);
	p->next = head.next;
	
	while( cnt < n ){
		
		p = head.next;
		if(p->protime = 0){
			
			p = p->next;
		}else if(p->protime > q){
			
			p->protime -= q;
			tcnt += q;
		}else if (p->protime <= q){
			
			p->protime = 0;
			tcnt += p->protime;
			printf("%s %d\n", p->proname, tcnt);
			cnt++;
		}
	}
	return 0;
	
}