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

struct Process {
  string name;
  int time;
};

int main() {
  int n, q;
  cin >> n >> q;

  queue<Process> pq;
  for (int i = 0; i < n; i++) {
    Process p;
    cin >> p.name >> p.time;
    pq.push(p);
  }

  int total_time = 0;
  while (!pq.empty()) {
    Process p = pq.front();
    pq.pop();
    total_time += p.time > q ? q : p.time;
    p.time -= q;
    if (p.time <= 0)
      cout << p.name << " " << total_time << endl;
    else
      pq.push(p);
  }

  return 0;
}
