#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, q;
  cin >> n >> q;
  queue<string> P;
  queue<int> T;
  for (int i = 0; i < n; i++){
    string p;
    int t;
    cin >> p >> t;
    P.push(p);
    T.push(t);
  }
  int t = 0;
  while (!P.empty()){
    string cp = P.front();
    int ct = T.front();
    P.pop();
    T.pop();
    if (ct <= q){
      t += ct;
      cout << cp << ' ' << t << endl;
    } else {
      ct -= q;
      t += q;
      P.push(cp);
      T.push(ct);
    }
  }
}
