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


signed main(){

  int n,q; cin >> n >> q;
  queue< pair<string,int> > que;
  for(int i = 0; i < n; i++){
    string s;
    int t;
    cin >> s >> t;
    que.push({s,t});
  }

  int t = 0;
  for(;!que.empty();){
    pair<string,int> p = que.front(); que.pop();
    if(p.second-q <= 0){
      t += p.second;
      cout << p.first << " " << t << endl;
    }
    else{
      t += q;
      que.push({p.first,p.second-q});
    }
  }

  return 0;
}

