#include<iostream>
#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define  ll long long
using namespace std;

int main()
{
int a,n,x,t,sum=0;
string name;
cin>>n>>x;
queue<pair<string,int> > q;
for(int i=1;i<=n;i++)
{
	cin>>name>>t;
	q.push(make_pair(name,t));
}
pair<string,int> u;
while(!q.empty())
{
	u=q.front();
	q.pop();
	a=min(u.second,x);
	u.second-=a;
	sum=sum+a;
	if(u.second>0)
	q.push(u);
	else
	{
		cout<<u.first<<" "<<sum<<"\n";
	}
}
return 0;
}
