#include <bits/stdc++.h>
using namespace std;
int n = 1;
long long sum = 0;
struct node
{
int num, start, time, pri;
bool operator<(const node &a) const
{
if(a.pri != pri) return a.pri < pri;
return a.start > start;
}
}a[500001];
node t;
priority_queue<node> q;
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int main()
{
while(cin >> t.num >> t.start >> t.time >> t.pri)
{
while(!q.empty() && sum + q.top().time <= t.start)
{
node u = q.top(); q.pop();
sum += u.time;
printf("%d %ld\n", u.num, sum);
}
if(!q.empty())
{
node u = q.top(); q.pop();
u.time = u.time - t.start + sum;
q.push(u);
}
q.push(t);
sum = t.time;
}
while(!q.empty())
{
node u = q.top(); q.pop();
sum += u.time;
printf("%d %ld\n", u.num, sum);
}
return 0;
}