C++#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define il inline
#define pii pair<int,int>
#define for0(n) for(int i=0;i<n;i++)
#define for1(n) for(int i=1;i<=n;i++)
#define FOR(i,a,b,c) for(int i=a;i<=b;i+=c)
#define REP(i,a,b,c) for(int i=a;i>=b;i-=c)
#define W(x) while(x--)
#define p_q priority_queue
using namespace std;
il ll read(){
ll s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
il void write(int x){
if(x==0){putchar('0');return;}
ll len=0,k1=x,c[10005];
if(k1<0)k1=-k1,putchar('-');
while(k1)c[len++]=k1%10+'0',k1/=10;
while(len--)putchar(c[len]);
}
struct node{
int id,st,re,pr;
bool operator < (const node &a)const{
if(pr==a.pr) return st>a.st;
else return pr<a.pr;
}
};
node c;
ll ti;
p_q<node>q;
int main(){
while(scanf("%d%d%d%d",&c.id,&c.re,&c.st,&c.pr)!=EOF){
while(!q.empty()&&ti+q.top().re<=c.st){
node b=q.top();
q.pop();
write(b.id);
putchar(' ');
write(ti+b.re);
puts("");
ti+=b.re;
}
if(!q.empty()){
node d=q.top();
q.pop();
d.re=d.re-c.st+ti;
q.push(d);
}
q.push(c);
ti=c.st;
}
while(!q.empty()){
node f=q.top();
q.pop();
ti+=f.re;
write(ti);
putchar(' ');
write(f.id);
puts("");
}
return 0;
}