#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
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;
priority_queue<node>q;
ll ti;
int main()
{
while(scanf("%d%d%d%d",&c.id,&c.st,&c.re,&c.pr)==4)
{
while(!q.empty()&&(ti+q.top().re<=c.st))
{
node b=q.top();q.pop();ti+=b.re;
printf("%d %lld\n",b.id,ti);
}
if(!q.empty())
{
node b=q.top();q.pop();
b.re-=c.st-ti;q.push(b);
}
q.push(c);
ti=c.st;
}
while(!q.empty())
{
node b=q.top();q.pop();
ti+=b.re;
printf("%d %lld\n",b.id,ti);
}
return 0;
}