#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<set>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
using namespace std;
#include<map>
map<int,int >m;
int main()
{
int n;
while(scanf("%d",&n),n){
int a,b;
int i;
m.clear();
m[1000000000]=1; // key值为1000000000 映射值:1;
for(i=0;i<n;i++){
scanf("%d%d",&a,&b);
printf("%d",a);
map<int,int>::iterator t=m.lower_bound(b);//寻找到 b<=最近
// printf("%d %d\n",t->second,t->first);
// t->second 表示映射值
// t->first 表示key值
if(t==m.end())//b为最大
{
t--;
printf(" %d\n",t->second);
}
else
{
int t1 = t->first;
int tmp = t->second;
if(t!=m.begin())
{
t--;
if(b-t->first<=t1-b)// b在中间 比较两端 差值
printf(" %d\n",t->second);
else printf(" %d\n",tmp);
}
else printf(" %d\n",t->second);// b最小
}
m[b]=a;// 加入
}
}
return 0;
}