# include <iostream>
# include <deque> 
using namespace std;
struct info
{
	char name[15];
	int sum;
};
int main(void)
{
	int n,deal;
	int Time = 0;
	deque<info> w;
	info tem;
	scanf("%d %d",&n,&deal);
	for(int i = 0;i < n;i++)
	{
		scanf("%s %d",&tem.name,&tem.sum);
		w.push_back(tem);
	}
	while(w.size())
	{
		if(w[0].sum <= deal)
		{
			Time += w[0].sum;
			printf("%s %d\n",w[0].name,Time);
			w.pop_front();
		}
		else
		{
			Time += deal;
			w[0].sum -= deal;
			w.push_back(w[0]); w.pop_front();
		}
	}
	return 0;
} 
