#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;

int main() {

	int n;
	while (cin >> n&&n) {
		vector<pair<int, int> >team(n);
		int s, m, id;
		for (int j = 0; j < n; j++) {
			cin >> id;
			team[j].second = id;
			team[j].first = 0;
			for (int i = 0; i < 4; i++) {
				cin >> m >> s;
				team[j].first += 60 * m + s;

			}
		}
		sort(team.begin(), team.end());
		for (int i = 0; i < 2; i++) {
			cout << team[i].second << endl;
		}
		cout << team[n - 2].second << endl;
	}

	return 0;
}