#include<iostream>
#include<algorithm>
#include<queue>
#include<string>

using namespace std;

int main()
{
	queue<pair<string,int> > q;//后面的两个>要用空格隔开 
	int n,tms;
	cin>>n>>tms;
	for(int i=0;i<n;i++){
		string name;
		int t;
		cin>>name>>t;
		q.push(make_pair(name,t));
	}
	pair<string,int> u;
	int cnt=0;
	while(!q.empty()){
		u=q.front();
		q.pop();
		cnt+=min(u.second,tms);
		u.second-=tms;
		if(u.second<=0)cout<<u.first<<' '<<cnt<<endl;
		else q.push(u);
	}
	return 0;
}
