#include<algorithm>
#include<set>
#include<map>
#include<iostream>
#include<cstdlib>
using namespace std;
map<int,int> club;//存储数据
map<int,int>::iterator st;
int n,id,power;
int a[100005];
int b[100005];
int main()
{
scanf("%d",&n);
club[1000000000]=1;
for(int i=0;i<n;i++)
{
scanf("%d%d",&id,&power);
st=club.lower_bound(power);
if(st==club.begin()){
//实力差劲
// printf("%d %d\n",id,st->second);
a[i]=id;
b[i]=st->second;
}
else if(st==club.end()){
//实力强劲
st--;
// printf("%d %d\n",id,st->second);
a[i]=id;
b[i]=st->second;
}
else{
//实力中
int right=st->first;
st--;
int left=st->first;
if(power-left<=right-power){
// printf("%d %d\n",id,st->second);
a[i]=id;
b[i]=st->second;
}
else{
st++;
// printf("%d %d\n",id,st->second);
a[i]=id;
b[i]=st->second;
}
}
club[power]=id;
}
for(int i=0;i<n;i++)
printf("%d %d\n",a[i],b[i]);
return 0;
}