#define MAX 200000

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

//?§???????.
typedef struct process {
	char name[11];
	int time;
}pro;

//????????????????????£?¨?.
void enqueue(pro x);
pro dequeue();
bool isFull();
bool isEmpty();

//??°?????????????????°.
pro pr[MAX];
int head = 0;
int tail = 0;

int main(void) {
	int i = 0;
	int n = 0;
	int q = 0;
	int t = 0;
	pro cell;

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

	//process?????£?¨???¨????????????.
	for (i = 0; i < n; i++) {
		scanf("%s", pr[i].name);
		scanf("%d", &pr[i].time);
	}

	tail = n;

	while (!isEmpty()) {
		cell = dequeue();
		if (cell.time - q <= 0) {
			t += cell.time;
			cell.time = 0;
			printf("%s %d\n", cell.name, t);
		}
		else if (cell.time > 0) {
			t += q;
			cell.time -= q;
			enqueue(cell);
		}
	}

	return 0;
}

void enqueue(pro x) {
	pr[tail] = x;

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

pro dequeue(void) {
	pro x = pr[head];

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

	return x;
}

bool isFull() {
	return head == (tail + 1) % MAX;
}

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