#include <stdio.h>
struct process_info_t {
	char name[11];
	int time;
};
typedef struct process_info_t ProcessInfo;

int main(void) {
	int num, qt, i, process, living_process;
	ProcessInfo rrs[100000];

	scanf("%d %d ", &num, &qt);
	for (i = 0; i < num; i++) {
		scanf("%10s %d ", rrs[i].name, &rrs[i].time);
	}

	process = 0;
	living_process = num;
	for (i = 0;; i = (i+1) % num) {
		if (!rrs[i].name[0])
			continue;
		rrs[i].time -= qt;
		if (rrs[i].time > 0) {
			process += qt;
		} else {
			process += qt + rrs[i].time;
			printf("%s %d\n", rrs[i].name, process);
			rrs[i].name[0] = '\0';
			if (--living_process <= 0)
				break;
		}
	}
	return 0;
}