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

#define DEF_ELM_MAX 100005

typedef struct _PROCESS
{
	char name[100];
	int time;
} PROCESS;

static int head;
static int tail;
static PROCESS Queue[DEF_ELM_MAX];

void enque(PROCESS x)
{
	Queue[tail++] = x;
	tail %= DEF_ELM_MAX;
}

PROCESS deque( void )
{
	PROCESS x = Queue[head++];
	head %= DEF_ELM_MAX;
	return x;
}

////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int main(void)
{
	int i;
	int N;
	int q;
	PROCESS p;
	int elaps = 0;
//
	scanf("%d %d", &N, &q);
	for ( i = 0 ; i < N ; i++ ) {
		scanf("%s %d", Queue[i].name, &Queue[i].time);
	}
	head = 0;
	tail = N;

	while (head != tail) {
		p = deque();
		if (p.time <= q) {
			elaps += p.time;
			printf("%s %d\n", p.name, elaps);
		} else {
			p.time -= q;
			elaps += q;
			enque(p);
		}

	}
	
	return 0;
}