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

class process{
public:
  string name;
  int time;
};

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

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

  int t = 0;
  while(que.size() > 0){
    process p = que.front();
    que.pop();
    if(p.time <= q){
      t += p.time;
      cout << p.name << " " << t << endl;
    }
    else{
      t += q;
      p.time -= q;
      que.push(p);
    }
  }

  return 0;
}

