#include <stdio.h>
#include <stdlib.h>
#define limit 11
typedef struct {
	int time;
	char name[limit];
}process_struct;

int main() {
	int i, j, processes, quantum, time;
	scanf("%d %d", &processes, &quantum);

	if (processes > 100000 || quantum > 1000) return 0;

	process_struct* process_array = (process_struct*)malloc(sizeof(process_struct)* processes);
	for (i = 0; i != processes; i++) {
		scanf("%s %d", process_array[i].name, &process_array[i].time);
	}

	i = 0;
	time = 0;
	while (1) {
		for (i = 0; i < processes; i++) {
			process_array[i].time -= quantum;

			if (process_array[i].time <= 0) {
				time += (process_array[i].time + quantum);
				printf("%s %d\n", process_array[i].name, time);
				for (j = i; j < processes - 1; j++) {
					process_array[j] = process_array[j + 1];
				}
				processes--;
				i--;
			}

			else time += quantum;
		}

		if (processes == 0) break;
	}

	free(process_array);
	return 0;
}


