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

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