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

int main() {
  int N, Q;
  cin >> N >> Q;
  queue<pair<string, int>> que;
  for (int i = 0; i < N; i++) {
    string name;
    int time;
    cin >> name >> time;
    que.push(make_pair(name, time));
  }
  int total_time = 0;
  while (que.size()) {
    auto p = que.front(); que.pop();
    total_time += min(p.second, Q);
    p.second -= Q;
    if (p.second <= 0) {
      cout << p.first << ' ' << total_time << endl;
    } else {
      que.push(p);
    }
  }
}
