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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef pair<int, int> PII;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;

		vector<PII> team(n);
		REP(i, n) {
			int m, s;
			scanf("%d", &team[i].second);
			team[i].first = 0;
			REP(j, 4) {
				scanf("%d %d", &m, &s);
				team[i].first += m * 60 + s;
			}
		}
		sort(team.begin(), team.end());
		printf("%d\n%d\n%d\n", team[0].second, team[1].second, team[team.size()-2].second);
	}
	return 0;
}