#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp
{
	char chName[20];
	int nT;
}P;

P In[LEN];
int nHead, nTail;
int n;

void enqueue(P x)
{
	In[nTail] = x;
	nTail = (nTail + 1) % (n + 2);
}

P dequeue()
{
	P ret = In[nHead];
	nHead = (nHead + 1) % (n + 2);
	return ret;
}

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