#include <queue>
#include <cctype>
#include <iostream>
#include <string>

using namespace std;

struct PS {
	string name;
	unsigned int t;
};

int main()
{
	unsigned int n, s, t = 0;
	queue<PS> ps;

	cin >> n >> s;

	for (unsigned int i = 0; i < n; ++i) {
		PS x;
		cin >> x.name >> x.t;
		ps.push(x);
	}

	while ( ! ps.empty()) {
		PS x;
		x = ps.front();
		ps.pop();

		if (x.t <= s) {
			t += x.t;
			cout << x.name << " " << t << endl;
		} else {
			t += s;
			x.t -= s;
			ps.push(x);
		}
	}

	return 0;
}

