#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

map<int, int>m;
pair<int, int>mm[100000];

int main() {
	int N;
	while (cin >> N, N) {
		for (int i = 0; i < N; i++) {
			int team;
			cin >> team;
			int m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			mm[i].first = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
			mm[i].second = team;
		}
		sort(mm,mm+N);
		//for (int i = 0; i < N; i++) {
		//	cout << mm[i].second << endl;
		//}
		cout << mm[0].second << endl << mm[1].second << endl << mm[N-2].second << endl;
	}
}
