#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<P> team(n);
		for(int i = 0; i < n; ++i)
		{
			int c1, m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			team[i].second = c1;
			team[i].first = (m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4);
		}
		sort(team.begin(), team.end());
		cout << team[0].second << endl;
		cout << team[1].second << endl;
		cout << team[n - 2].second << endl;
	}
}

int main()
{
	solve();
	return(0);
}