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

typedef struct pp{
  char name[100];
  int t;
}P;

int main(){
  int i,n,q,sum=0,x;
  string s;
  P A[1000];
  queue<string> Name;
  queue<int> Time;

  cin >> n >> q;

  for(i=0;i<n;i++){
    cin >> A[i].name >> A[i].t;
    Name.push(A[i].name);
    Time.push(A[i].t);
  }
  while(Name.empty()==0){
    s=Name.front();
    x=Time.front();
    if(x<=q){
      sum+=x;
      cout << s << " " << sum <<endl;
    }
    else{
      sum+=q;
      x-=q;
      Name.push(s);
      Time.push(x);
    }
    Name.pop();
    Time.pop();
  }
  return 0;
}
