// Queue
#include <stdio.h>

int main() {
	int q=0, time=0, tmp=0, tmp0=0, tmp1=0, tmp2=0, tmp3=0, p[50000];
	char name[50000][10];
	scanf("%d %d", &time, &q);
	while (tmp<time) {
		scanf("%s %d", name[tmp], &p[tmp]);
		tmp++;
	}

	for (tmp=time;tmp!=0;) {
		// printf("%d\n",tmp);
		for (tmp0=0;tmp0<=time;tmp0++) {
			// if (tmp0>=time) tmp0=0;
			if (p[tmp0]>0) {
				// printf("    %s\n",name[tmp0]);
				p[tmp0]-=q;
				tmp2+=q;
				if (p[tmp0]<=0) {
					tmp2=tmp2+p[tmp0];
					tmp--;
					printf("%s %d\n", name[tmp0], tmp2);
				}
			}
		}
	}
	// printf("end\n");
	return 0;
}