#include <iostream>
#include <queue>

using namespace std;

typedef pair<string,int> P;

int main(){
  int n,q,Time;
  queue<P> Q;
  string name;

  cin >> n >> q;
  for(int i = 0 ; i < n ; i++){
    cin >> name >> Time;
    Q.push(P(name,Time));
  }

  int ans = 0;
  while(!Q.empty()){
    P p = Q.front(); Q.pop();

    if(p.second <= q){
      ans += p.second;
      cout << p.first << " " << ans << endl;
    }else{
      ans += q; 
      p.second -= q;
      Q.push(p);
    }
  }

  return 0;
}