#include <bits/stdc++.h>
using namespace std;
typedef pair<string,int> Pair;
int main(){

	int n; cin >> n;
	int q; cin >> q;
	queue<Pair> Q;
	int sum_time=0;

	for(int i=0; i<n; i++){
		string s; int time;
		cin >> s >> time;
		Q.push(Pair(s,time));
	}

	while(!Q.empty()){
		Pair p = Q.front();
		Q.pop();
		if(p.second<=q){
			sum_time += p.second;
			cout << p.first << " " << sum_time << endl;
		}
		else{
			sum_time += q;
			Q.push(Pair(p.first, p.second - q));
		}
	}
	return 0;
}