#include #include #include #include using namespace std; int main() { int n, id, p; while(cin >> n,n) { mapmp; mp[1000000000]=1; for(int i=1; i<=n; i++) { scanf("%d%d",&id,&p); map::iterator it=mp.lower_bound(p); if(it==mp.begin()) cout << id << " " << it->second <::iterator a=it, b=--it; if((a->first)-p>=p-(b->first))cout << id << " " << b->second <second <