#include <stdio.h>

int main(void)
{
	int n, quantum, i;
	scanf("%d", &n);			// ??????????????°
	scanf("%d", &quantum);		// ???????????????

	char pname[100000][10];
	int ptime[100000];
	for (i=0; i<n; i++) {
		scanf("%s", &pname[i]);	// ???????????????
		scanf("%d", &ptime[i]);	// ????????????????????????
	}

	int time=0;					// ????????????
	int prev_time = time;		// ??????????????¨????????°
	while (1) {
		for (i=0; i<n; i++) {
			if (ptime[i]>0) {
				if (ptime[i]-quantum<=0) {
					time += ptime[i];
					ptime[i] = 0;
					printf("%s ", pname[i]);
					printf("%d\n", time);
				} else {
					ptime[i] -= quantum;
					time += quantum;
				}
			}
		}
		if (prev_time == time) return 0;
		prev_time = time;
	}

}

/*

from: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp

example:

5 100
p1 150
p2 80
p3 200
p4 350
p5 20

*/