#include <bits/stdc++.h>
using namespace std;
int n;
map<int, pair<string, string>> mp;
int main()
{
cin >> n;
while (n--)
{
string a, b;
int x;
cin >> a >> b >> x;
mp[x].first = a, mp[x].second = b;
}
cout << mp.rbegin()->second.first << " " << mp.rbegin()->second.second << endl;
cout << mp.begin()->second.first << " " << mp.begin()->second.second << endl;
return 0;
}