#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, q, now = 0, c;
	cin >> n >> q;

	vector<string> name(n);
	vector<int> time(n);
	queue<int> Q;

	for (int i = 0; i < n; ++i) {
		cin >> name.at(i) >> time.at(i);
		Q.push(i);
	}

	while (Q.size() > 0) {
		c = Q.front();
		Q.pop();
		if (time.at(c) > q) {
			time.at(c) -= q;
			now += q;
			Q.push(c);
		} else {
			now += time.at(c);
			cout << name.at(c) << " " << now << endl;
		}
	}
}
