#include <bits/stdc++.h>
using namespace std;

int main(){
	int n, q;
	scanf("%d%d", &n, &q);
	string name;
	int time;
	queue<pair<string, int> > que;
	for(int i = 0; i < n; i++) {
		cin >> name >> time;
		que.push(make_pair(name, time));
	}
	int count = 0;
	while(!que.empty()) {
		pair<string, int> query = que.front(); que.pop();
		if(query.second <= q) {
			count += query.second;
			cout << query.first << " " << count << '\n';
		}else{
			count += q;
			query.second -= q;
			que.push(query);
		}
	}
}

