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

typedef struct process {
	string name;
	int time;
} Prc;
int main() {
	int n, q;
	Prc p;
	queue<Prc> Q;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> p.name >> p.time;
		Q.push(p);
	}
	long long T = 0;
	while (!Q.empty()) {
		if (Q.front().time > q) {
			T += q;
			p.name = Q.front().name;
			p.time = Q.front().time - q;
			Q.pop();
			Q.push(p);
		}
		else {
			T += Q.front().time;
			cout << Q.front().name << " " << T << endl;
			Q.pop();
		}
	}
}
