#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#define maxSize 100000

struct process_ {
	char name[10];
	int time;
};

struct process_ my_queue[maxSize];
int rear=0, front=0;

void enqueue(struct process_ x) {
    my_queue[rear] = x;
	rear=(rear + 1) % maxSize;
}

struct process_ dequeue() {
	struct process_ value = my_queue[front];
	front = (front + 1) % maxSize;
	return value;
}
bool isEmpty(struct process_ my_queue[]) {
	if (front == rear)
		return true;
	else
		return false;
}

int main() {
	int n, q,countTime=0;
	scanf("%d%d", &n, &q);
	struct process_ p;
	for (int i = 0; i < n; i++) {
		scanf("%s%d", &p.name, &p.time);
		//printf("%s %d", p.name, p.time);
		enqueue(p);
	}
	while (!isEmpty(my_queue)) {
		struct process_ my_p = dequeue();
		if (my_p.time > q) {
			my_p.time -= q;
			countTime += q;
			enqueue(my_p);
		}
		else {
			countTime += my_p.time;
			printf("%s %d\n", my_p.name, countTime);
		}
	}
	return 0;
}
