#include <stdio.h>


typedef struct{
	char name[11];
	int time;
}DATA_T;


int main()
{
	char in_str[30];
	int n, q;
	DATA_T *process;
	int *ring_queue;
	int head, end;
	int time;
	int i, j;


	fgets(in_str, sizeof(in_str), stdin);
	sscanf(in_str, "%d %d", &n, &q);

	process = (DATA_T *)malloc(sizeof(DATA_T) * n);
	ring_queue = (int *)malloc(sizeof(int) * (n + 1));

	for(i = 0; i < n; i++){
		fgets(in_str, sizeof(in_str), stdin);
		sscanf(in_str, "%s %d", &process[i].name, &process[i].time);
	}

	for(i = 0; i < n; i++)
		ring_queue[i] = i;


	head = time = 0;
	end = n;
	// キューが空になるまで処理をする
	while(head != end){
		if(process[ring_queue[head]].time - q > 0){
			process[ring_queue[head]].time -= q;
			time += q;
			ring_queue[end] = ring_queue[head];
			end = (end + 1) % (n + 1);
			head = (head + 1) % (n + 1);
		}else{
			time += process[ring_queue[head]].time;
			printf("%s %d\n", process[ring_queue[head]].name, time);
			head = (head + 1) % (n + 1);
		}
	}

	return 0;
}
