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

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

Process *Q;
int head;
int tail;
int n;

Process dequeue();
void enqueue(Process);

int main() {
	int ms;
	int i;
	Process deq;
	int run = 0;

	scanf("%d%d", &n, &ms);

	head = 0;
	tail = 0;
	n++;

	Q = (Process *)malloc(n * sizeof(Process));
	for (i = 0; i < n - 1; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].time);
		Q[i].flag = 1;
		tail++;
	}

	Q[i].flag = 0;

	i = 0;
	while (head != tail) {

		if (Q[i].flag == 1) {

			if (Q[i].time <= ms) {
				run += Q[i].time;
				deq = dequeue();
				printf("%s %d\n", deq.name, run);
			}

			else {
				run += ms;
				Q[i].time -= ms;

				deq = dequeue();
				enqueue(deq);
			}
		}

		i++;
		if (i == n)
			i = 0;
	}

	free(Q);
	return 0;
}

Process dequeue() {
	Process x;

	x = Q[head];
	x.flag = 0;

	if (head + 1 == n)
		head = 0;
	else
		head++;

	return x;
}

void enqueue(Process x) {
	
	Q[tail] = x;
	Q[tail].flag = 1;

	if (tail + 1 == n)
		tail = 0;
	else
		tail++;
}
