RT
#include<bits/stdc++.h>
using namespace std;
long long Time;
struct node{
int sum,tm1,tm2,yx;
bool operator < (const node &a) const {
if(yx==a.yx) return tm1>a.tm1;
else return yx<a.yx;
}
}n;
priority_queue<node>q;
int main(){
while(scanf("%d%d%d%d",&n.sum,&n.tm1,&n.tm2,&n.yx)){
while(!q.empty()&&Time+q.top().tm2<=n.tm1){
node s=q.top();
q.pop();
printf("%d %lld\n",s.sum,Time+s.tm2);
Time+=s.tm2;
}
if(!q.empty()){
node s=q.top();
q.pop();
s.tm2=s.tm2-n.tm1+Time;
q.push(s);
}
q.push(n);
Time=n.tm1;
}
while(!q.empty()){
node s=q.top();
q.pop();
Time+=s.tm2;
printf("%d %lld\n",s.sum,Time);
}
return 0;
}