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

struct TaskStruct
{
	char name[12];
	int time;
};
typedef struct TaskStruct Task;

#define QUEUE_SIZE 100000
struct QueueStruct
{
	int head, tail;
	Task data[QUEUE_SIZE];
};
typedef struct QueueStruct Queue;

void queue_clear(Queue *queue)
{
	queue->head = 0;
	queue->tail = 0;
}

int queue_empty(Queue *queue)
{
	return (queue->head == queue->tail);
}

Task queue_dequeue(Queue *queue)
{
	Task task = queue->data[queue->head++];
	queue->head %= QUEUE_SIZE;
	return task;
}

void queue_enqueue(Queue *queue, Task task)
{
	queue->data[queue->tail++] = task;
	queue->tail %= QUEUE_SIZE;
}

void queue_dump(Queue *queue)
{
	printf("[");
	for(int i = queue->head; i != queue->tail; i = (i+1)%QUEUE_SIZE)
	{
		Task task = queue->data[i];
		printf(" %s(%d)", task.name, task.time);
	}
	printf(" ]\n");
}

int main()
{
	int n, t, quantum;
	Queue queue;
	queue_clear(&queue);

	scanf("%d %d", &n, &quantum);
	for(int i = 0; i < n; ++i)
	{
		Task task;
		scanf("%s %d", task.name, &task.time);
		queue_enqueue(&queue, task);
	}

	t = 0;
	while(!queue_empty(&queue))
	{
		//queue_dump(&queue);
		Task task = queue_dequeue(&queue);
		if(task.time <= quantum)
		{
			t += task.time;
			printf("%s %d\n", task.name, t);
		}
		else
		{
			task.time -= quantum;
			t += quantum;
			queue_enqueue(&queue, task);
		}
	}
}

