// id: ALDS1_3_B
// CPU: 00:01sec  Memory: 3348KB
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define NAME_LEN 10

struct Process;
struct Node;
struct Queue_type;
typedef struct Process Item;
typedef struct Node *PtrToNode;
typedef PtrToNode Position;
typedef struct Queue_type *Queue;

struct Process {
	char pid[NAME_LEN + 1];
	int rest;
};

struct Node {
	Item data;
	Position next;
};

struct Queue_type {
	Position front;
	Position rear;
};

Queue create(void);
void destroy(Queue q);
void make_empty(Queue q);
bool is_empty(Queue q);
void enqueue(Queue q, Item i);
Item front(Queue q);
Item dequeue(Queue q);
static void terminate(const char *message);

int main(void)
{
	int n, slice;
	Queue processes = create();
	int time = 0;

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

	for ( int i = 0; i < n; ++i ) {
		Item process;

		scanf("%s%d", process.pid, &process.rest);
		enqueue(processes, process);
	}

	while ( !is_empty(processes) ) {
		Item process = dequeue(processes);

		if ( process.rest > slice ) {
			process.rest -= slice;
			time += slice;
			enqueue(processes, process);
		}
		else {
			time += process.rest;
			printf("%s %d\n", process.pid, time);
		}
	}

	destroy(processes);

	return 0;
}

Queue create(void)
{
	Queue q;

	q = malloc(sizeof(struct Queue_type));
	if ( q == NULL )
		terminate("Error in create: queue could not be created.");

	q->front = malloc(sizeof(struct Node));
	if ( q->front == NULL ) {
		free(q);
		terminate("Error in create: fail to allocate space for the header.");
	}

	q->front->next = NULL;

	q->rear = q->front;

	return q;
}

void destroy(Queue q)
{
	make_empty(q);

	free(q->front);
	free(q);
}

void make_empty(Queue q)
{
	while ( !is_empty(q) )
		dequeue(q);
}

bool is_empty(Queue q)
{
	return q->front->next == NULL;
}

void enqueue(Queue q, Item i)
{
	Position tmp = malloc(sizeof(struct Node));

	if ( tmp == NULL ) {
		destroy(q);
		terminate("Error in enqueue: fail to allocate space for new node.");
	}

	tmp->data = i;
	tmp->next = NULL;

	q->rear->next = tmp;
	q->rear = tmp;
}

Item front(Queue q)
{
	if ( is_empty(q) ) {
		destroy(q);
		terminate("Error in front: queue is empty.");
	}

	return q->front->next->data;
}

Item dequeue(Queue q)
{
	Item item;
	Position tmp;

	if ( is_empty(q) ) {
		destroy(q);
		terminate("Error in dequeue: queue is empty.");
	}

	tmp = q->front->next;
	item = tmp->data;
	q->front->next = tmp->next;

	if ( q->rear == tmp )
		q->rear = q->front;

	free(tmp);

	return item;
}

static void terminate(const char *message)
{
	printf("%s\n", message);
	exit(EXIT_FAILURE);
}
