#include <stdio.h>
#include <stdlib.h>

typedef struct {
	char name[12];
	int time;
} process;

int main(void) {
	int now = 0, N, q, i, rem;
	process *ps;
	scanf("%d %d", &N, &q);
	ps = malloc(sizeof(process) * N);
	for (i = 0; i < N; i++) {
		scanf("%s %d", ps[i].name, &ps[i].time);
	}
	rem = N;
	i = 0;
	while (rem) {
		if (ps[i].time != -1) {
			if (ps[i].time <= q) {
				now += ps[i].time;
				printf("%s %d\n", ps[i].name, now);
				rem--;
				ps[i].time = -1;
			} else {
				now += q;
				ps[i].time -= q;
			}
		}
		if (++i >= N) i = 0;
	}
}