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

typedef struct Node {
	struct Node *next;
	char name[11];
	int time;
} NODE;

NODE *front = NULL;
NODE *rear = NULL;

void enqueue(char *name, int time)
{
	NODE *tmp = (NODE *)malloc(sizeof(NODE));
	memcpy(tmp->name, name, sizeof(tmp->name));
	tmp->time = time;
	tmp->next = NULL;

	if (front == NULL) {
		front = rear = tmp;
	}
	else {
		rear->next = tmp;
		rear = tmp;
	}
}

int dequeue(NODE *node)
{
	if (front != NULL) {
		memcpy(node, front, sizeof(NODE));
		free(front);
		front = node->next;
		return 1;
	}
	else {
		return 0;
	}
}

int main(int argc, char** argv)
{
	int i, proc_num, q, time;
	char name[11];

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

	for (i = 0; i < proc_num; i++) {
		scanf("%s %d", name, &time);
		enqueue(name, time);
	}

	int total_t = 0;

	while (1) {
		NODE node;
		if (dequeue(&node)) {
			int time_left = node.time - q;

			if (time_left > 0) {
				enqueue(node.name, time_left);
				total_t += q;
			}
			else {
				printf("%s %d\n", node.name, total_t + node.time);
				total_t += node.time;
			}
		}
		else {
			break;
		}
	}
	return 0;
}