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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<pair<long long,int> > team;
		int num,m1,m2,m3,m4,s1,s2,s3,s4;
		
		rep(i,n)
		{
			cin >> num >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;

			long long time = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
			team.push_back(make_pair(time,num));
		}

		sort(team.begin(),team.end());

		cout << team[0].second << endl << team[1].second << endl << team[n-2].second << endl;
	}
	return 0;
}