#include <stdio.h>

int main(int argc, char const *argv[]) {
	char name[1000][11], ansname[1000][11];
	int ptime[100000], anstime[100000];
	int time = 0;
	int i, j, k, n, q, rest;
	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++) {
		scanf("%s %d", name[i], &ptime[i]);
	}
	rest = n;
	while (rest != 0) {
		for (i = 0; i < n; i++) {
			if (ptime[i] <= q && ptime[i] != -1) {
				time += ptime[i];
				ptime[i] = -1;
				printf("%s %d\n", name[i], time);
				rest--;
			} else if (ptime[i] != -1) {
				time += q;
				ptime[i] -= q;
			}
		}
	}
	return 0;
}