solution
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
string fir, en;
int first1=0x3f3f3f,end1;
int main()
{
int n;
while (cin >> n)
{
for (int i = 1; i <= n; i++)
{
string temp;
int x1, x2, x3, y1, y2, y3;
cin >> temp;
scanf("%d:%d:%d",&x1,&x2,&x3);
scanf("%d:%d:%d",&y1,&y2,&y3);
int temp1 = x1 * 3600 + x2 * 60 + x3;
int temp2 = y1 * 3600 + y2 * 60 + y3;
//cout<<temp1<<" "<<first1<<endl;
if (temp1 < first1)
{
first1 = temp1;
fir = temp;
}
if (temp2 > end1)
{
end1 = temp2;
en = temp;
}
}
cout << fir << " " << en;
}
}