#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

typedef tuple<int, int> P;

int main() {
	int n;
	while ( cin >> n, n ) {
		vector<P> v;
		for (int i = 0; i < n; ++i) {
			int c; cin >> c;
			int t = 0;
			for (int i = 0; i < 4; ++i) {
				int m, s; cin >> m >> s;
				t += m * 60 + s;
			}
			v.push_back( P(c, t) );
		}
		sort(v.begin(), v.end(), [](const P& p1, const P& p2) {
			return get<1>(p1) < get<1>(p2);
		});
		cout << get<0>(v[0]) << endl;
		cout << get<0>(v[1]) << endl;
		cout << get<0>(v[n-2]) << endl;
	}
}