#include <bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define mem(arr,val) memset((arr),(val),(sizeof(arr)))
using namespace std;
struct com {LL num,intime,dotime,tip;};
bool operator<(com a,com b) {return a.tip!=b.tip?a.tip<b.tip:a.intime>b.intime;}
priority_queue <com> wait;
int main(int argc,char *argv[])
{
LL a,b,c,d,t = 0;
while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d))
{
while(!wait.empty() && t+wait.top().dotime <= b)
{
com tmp = wait.top();
wait.pop();
printf("%lld %lld\n",tmp.num,tmp.intime+tmp.dotime);
t += tmp.dotime;
}
if(!wait.empty())
{
com tmp = wait.top();
wait.pop();
tmp.dotime = tmp.dotime-b+t;
wait.push(tmp);
}
wait.push((com){a,b,c,d});
t = b;
}
while(!wait.empty())
{
com tmp = wait.top();
wait.pop();
t += tmp.dotime;
printf("%lld %lld\n",tmp.num,t);
}
return 0;
}