#include<iostream>
using namespace std;
int head,tail,n;
struct task
{
	char name[100];
	int time;
}t,Q[1000000];
void enqueue(task x)
{
	Q[tail]=x;
	tail++;
}
task dequeue()
{
	task x=Q[head];
	head++;
	return x;
}
int main()
{
	int q;
	cin>>n>>q;
	for(int i=1;i<=n;i++)
		cin>>Q[i].name>>Q[i].time;
	head=1;
	tail=n+1;
	int sum=0;
	while(head!=tail)
	{
		t=dequeue();
		if(t.time>q)
		{
			sum+=q;
			t.time-=q;
			enqueue(t);
		}
		else
		{
			sum+=t.time;
			cout<<t.name<<' '<<sum<<endl;
		}
	}
	return 0;
}
