#include<bits/stdc++.h>
#define endl '\n'
#define prque priority_queue
#define int long long
using namespace std;
const int N=15005;
struct task{
int o;
int a;
int t;
int pr;
};
bool operator < (task a,task b){
if(a.pr!=b.pr) return a.pr<b.pr;
else return a.a>b.a;
}
int o,a,t,p,ti;
prque<task> q;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
task x;
while(cin>>x.o>>x.a>>x.t>>x.pr){
while(q.size() && ti+q.top().t<x.a){
task z=q.top();q.pop();
ti+=z.t;
cout<<z.o<<' '<<ti<<endl;
}
if(q.size()){
task z=q.top();q.pop();
z.t-=x.a-ti;
q.push(z);
}
q.push(x);
ti=x.a;
}
while(q.size()){
task z=q.top();q.pop();
ti+=z.t;
cout<<z.o<<' '<<ti<<endl;
}
return 0;
}