#include <bits/stdc++.h>

using namespace std;

class Team {
public:
	int id;
	int time;
};

Team TeamData[10000];

bool cmp(const Team& t1, const Team& t2) {
	return t1.time < t2.time;
}

int main(void) {
	int n, m, s, sum;

	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> TeamData[i].id;
			sum = 0;
			for (int j = 0; j < 4; j++) {
				cin >> m >> s;
				sum += m * 60 + s;
			}
			TeamData[i].time = sum;
		}

		sort(TeamData, TeamData + n,cmp);
		cout << TeamData[0].id << endl << TeamData[1].id << endl << TeamData[n - 2].id << endl;
	}

	return 0;
}
