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

int main(void) {
	int n = 0,q,t = 0,i,r,p[131072] = {0};
	char s[131072][16];
	scanf("%d%d",&n,&q);
	r = n;
	for(i = 1;i <= n;i++){
		scanf("%s%d",s[i],&p[i]);
	}
	while(r){
		for(i = 1;i <= n;i++){
			if(!(p[i])) continue;
			if(p[i] <= q){
				t+=p[i];
				p[i] = 0;
				printf("%s %d\n",s[i],t);
				r--;
			}
			if(p[i] > q){
				t+=q;
				p[i]-=q;
			}
		}
	}
	return 0;
}