#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll j,n,x,m,t;
struct asd{
ll num,t1,t2,w,run;
};
asd a[10000005];
asd c;
priority_queue<asd,vector<asd>,less<asd> >q;
bool operator <(asd x,asd y) {
if(x.w==y.w){
return x.t1<y.t1;
}
return x.w>y.w;
}
int main(){
n=1;
while(cin>>a[n].num>>a[n].t1>>a[n].t2>>a[n].w){
a[n].run=a[n].t2-a[n].t1;
n++;
}
t=1;
for(int i=1;i<=n;i++){
if(c.num==0){
if(!q.empty()){
asd tmp=q.top();
q.pop();
c=tmp;
}
else{
c=a[i];
}
}
else{
if(c.w<a[i].w){
if(c.run-a[i].t1-c.t1<=0){
t+=c.run;
cout<<c.num<<" "<<t<<endl;
c.num=0;
}
else{
q.push(c);
}
c=a[i];
}
}
}
return 0;
}