include[HTML_REMOVED]
using namespace std;
int main()
{
string id1,open_time1;
string id2,close_time1;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
string id3,open_time2,close_time2;
cin>>id3>>open_time2>>close_time2;
//更新开门
if(i==0||open_time2<open_time1)
{
id1=id3;
open_time1=open_time2;
}
//更新关门
if(i==0||close_time2>close_time1)
{
id2=id3;
close_time1=close_time2;
}
}
cout<<id1<<" "<<id2;
return 0;
}