#include <stdio.h>

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