#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

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

