#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 5100
#include<queue>
using namespace std;
struct node
{
int x,y;
int id;
bool operator<(const node &t)const
{
return y>t.y;
}
} hang[maxn],lie[maxn];
bool cmp(const node &a,const node &b)
{
return a.x<b.x;
}
int h[maxn],l[maxn];
priority_queue<node>q;
int main()
{
int n;
while(scanf("%d",&n)&&n)
{
for(int i=; i<n; i++)
{
scanf("%d%d%d%d",&hang[i].x,&lie[i].x,&hang[i].y,&lie[i].y);
hang[i].id=lie[i].id=i;
h[i]=;
l[i]=;
}
sort(hang,hang+n,cmp);
int cur=;
int timer=;
bool flag=;
while(!q.empty())q.pop();
while()
{
while(cur<n&&hang[cur].x<=timer)q.push(hang[cur++]);
if(timer<=n&&q.empty())
{
flag=;
break;
}
node v=q.top();
q.pop();
if(timer<v.x||timer>v.y)
{
flag=;
break;
}
h[v.id]=timer;
timer++;
if(timer>n)break;
}
if(flag)
{
sort(lie,lie+n,cmp);
cur=;
timer=;
while(!q.empty())q.pop();
while()
{
while(cur<n&&lie[cur].x<=timer)q.push(lie[cur++]);
if(timer<=n&&q.empty())
{
flag=;
break;
}
node v=q.top();
q.pop();
if(timer<v.x||timer>v.y)
{
flag=;
break;
}
l[v.id]=timer;
timer++;
if(timer>n)break;
}
}
for(int i=;i<n;i++)
if(l[i]==||h[i]==)
{
flag=;
break;
}
if(flag)
{
for(int i=; i<n; i++)
printf("%d %d\n",h[i],l[i]);
}
else puts("IMPOSSIBLE");
}
return ;
}