#include <iostream>
#include <map>

using namespace std;

int main(){
    int n;
    string sign,start,end;
    map<string,string> startMap,endMap;
    while (cin>>n){
        for (int i = 0; i < n; ++i) {
            cin>>sign>>start>>end;
            startMap[start] = sign;
            endMap[end] = sign;
        }
        map<string,string>::iterator it1,it2;
        it1 = startMap.begin();
        it2 = endMap.end();
        it2--;
        cout<<it1->second<<" "<<it2->second<<endl;
    }

    return 0;
}