#include<iostream>
#include<queue>
using namespace std;

int main(){
    int n,q;
    int a,time=0;
    string s;
    queue<int> Q;
    queue<string> name;

    cin >> n >> q;
    for(int i=0;i<n;i++){
        cin >> s >> a;
        Q.push(a);
        name.push(s);

    }

    while(Q.empty()==false){
        a=Q.front();
        s=name.front();
        if(a>=q){
            time+=q;
            a-=q;
            Q.pop();
            name.pop();
            Q.push(a);
            name.push(s);
        }else{
            time+=a;
            a=0;
            cout << name.front() << " " << time << endl;
            name.pop();
            Q.pop();
        }
    }

    return 0;
}