    #include <bits/stdc++.h>
    #include <fstream>

    using namespace std;
    #define forn(i,n) for(long long  i = 0; i<n;i++)

    class Monster{
    public:
        long long t;
        long long  h;
        long long  id;
        long long  time;
        long long  buy = 0 ;
        bool operator<(const Monster& k) const{

        if(t != k.t)
            return t < k.t;
        if (buy!=k.buy) return k.buy<buy;
        return id < k.id;
    }
    };


    int main()
    {
        ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//ifstream cin("queue.in ");
//ofstream cout("queue.out");
        long long  n, m, k;
        cin>>n>>m>>k;
        long long  cnt_m = 0;
        vector<long long > monster(n);
        set <Monster> qu;
        forn(i,n){
            Monster tmp;
            long long  t,h;
            cin>>t>>h;
            tmp.t=t;
            tmp.id = i;
            tmp.h = h;
            qu.insert(tmp);
        }
        long long  pred = 0;
        queue<long long > vec;
        while(!qu.empty()){
                Monster f = *qu.begin();
                qu.erase(qu.begin());
                if (f.buy == 1){
                    monster[f.id] = f.t;
                    cnt_m --;
                }else if(cnt_m<m){

                    f.buy = 1;
                    cnt_m++;
                    long long  t = f.t;
                    f.t=max(pred,t) + f.h;
                    pred= f.t;
                    qu.insert(f);
                    vec.push(pred);
                }else{

                    f.t += max((vec.front()-f.t + k - 1)/k * k,k);
                    vec.pop();
                    qu.insert(f);
                    }


        }


    for(auto i : monster) cout<<i<<"\n"
        ;
    }
