#include <stdio.h>
#include <stdlib.h>
#define LEN 100005

typedef struct pp {
	char name[100];
	int timeNeeded;
}P;

void enqueue(P);
P dequeue();
int isEmpty();

P Q[LEN + 1];
int head, tail, n;

int main() {
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);
	
	for (i = 0; i < n; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].timeNeeded);
		enqueue(Q[i]);
	}
	if (n == 1) {
		printf("%s %d\n", Q[0].name, Q[0].timeNeeded);
		return 0;
	}

	while(!isEmpty()){
		u = dequeue();
		if (u.timeNeeded > q) {
			u.timeNeeded -= q;
			elaps += q;
			enqueue(u);
		}
		else {
			elaps += u.timeNeeded;
			printf("%s %d\n", u.name, elaps);
		}
	}

	return 0;
}

void enqueue(P x) {
	Q[tail] = x;
	(tail + 1 > n) ? tail = 0 : tail++;
}

P dequeue() {
	P x = Q[head];
	(head + 1 > n) ? head = 0 : head++;
	return x;
}

int isEmpty() {
	return head == tail;
}

int isFull() {
	return head == (tail + 1) % n;
}

