#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

bool cmp(pii lhs, pii rhs)
{
	return (lhs.second < rhs.second);
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector <pii> p(n);
		
		for (int i = 0; i < n; i++){
			int num, t = 0;
			cin >> num;
			for (int j = 0; j < 4; j++){
				int m, s;
				cin >> m >> s;
				t += m * 60 + s;
			}
			p[i] = make_pair(num, t);
		}
		
		sort(p.begin(), p.end(), cmp);
		
		cout << p[0].first << endl << p[1].first << endl << p[n - 2].first << endl;
	}
	
	return (0);
}