#include <bits/stdc++.h>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
	int n, a, b = 0;
	int m, s;
	vector<P> v;
	while (1)
	{
		v.clear();
		cin >> n; if (n==0)
		{
			return 0;
		}
		REP(i, n)
		{
			cin >> a;
			REP(j, 4){
				cin >> m >> s;
				b = b + m * 60 + s;
			}
			v.push_back(P(b, a));
			b = 0;
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl
			<< v[1].second << endl
			<< v[n - 2].second << endl;
		
	}
	return 0;
}