#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
int id;
int Time;
int tim;
int first;
};
bool operator < (const node& a,const node& b){
if (a.first!=b.first) return a.first<b.first;
return a.Time>b.Time;
}
priority_queue <node> Q;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int a,b,c,d;
int ti;
while (cin>>a>>b>>c>>d){
if (Q.empty()){
Q.push((node){a,b,c,d});
ti=b;
continue;
}
int t=b-ti;
while (Q.size() && t>=Q.top().tim){
cout<<Q.top().id<<" "<<ti+Q.top().tim<<'\n';
t-=Q.top().tim;
Q.pop();
}
if (Q.size()){
node f;
f=Q.top();
Q.pop();
f.tim-=t;
Q.push(f);
}
ti=b;
Q.push((node){a,b,c,d});
}
while (Q.size()){
cout<<Q.top().id<<" "<<ti+Q.top().tim<<'\n';
ti+=Q.top().tim;
Q.pop();
}
return 0;
}