#include <stdio.h>

typedef struct {
	int suuji;
	char name[10];
}Que;

int head, tail, samplesuu;
Que hairetu[100000];

void enqueue(Que x);
Que dequeue(void);


void enqueue(Que x) {

	hairetu[tail] = x;
	if (tail == samplesuu) {
		tail = 0;
	}
	else
		tail++;
}

Que dequeue(void) {
	Que x;
	x = hairetu[head];
	if (head  == samplesuu) {
		head = 0;
	}
	else
		head++;
	return x;
}

int main(void) {
	int quantum, time;
	time = 0;

	scanf("%d %d", &samplesuu, &quantum);

	for (int i = 0; i < samplesuu; i++) {
		scanf("%s", &hairetu[i].name, 100);
		scanf("%d", &hairetu[i].suuji);
	}

	head = 0;
	tail = samplesuu;

	Que hairetu2;
	

	while (head != tail) {
		hairetu2 = dequeue();
		if (hairetu2.suuji > quantum) {
			hairetu2.suuji -= quantum;
			time += quantum;
			enqueue(hairetu2);
		}
		else {
			time += hairetu2.suuji;
			printf("%s %d\n", hairetu2.name, time);
		}


	}
	return 0;
}



