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

#define LEN 100005

typedef struct pp
{
	char chName[10];
	int nTime;
} Pair;

Pair PIn[LEN];
int nHead, nTail, n;

Pair dequeue()
{
	Pair PTemp = PIn[nHead];
	nHead = (nHead + 1) % (n + 2);
	return PTemp;
}

void enqueue(Pair in)
{
	PIn[nTail] = in;
	nTail = (nTail + 1) % (n + 2);
}

int main()
{
	int q, nCT = 0;
	Pair PTemp;
	scanf("%d %d", &n, &q);
	for (int i = 0; i < n; ++i)
	{
		scanf("%s %d", PIn[i].chName, &PIn[i].nTime);
	}
	nHead = 0;
	nTail = n;
	while (nHead != nTail)
	{
		PTemp = dequeue();
		if (PTemp.nTime <= q)
		{
			nCT += PTemp.nTime;
			printf("%s %d\n", PTemp.chName, nCT);
		}
		else
		{
			nCT += q;
			PTemp.nTime -= q;
			enqueue(PTemp);
		}
	}
	return 0;
}
