# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
using namespace std;

int main() {
	int n;
	while (cin >> n&&n != 0) {
		vector<pair<long long, long long>> result;
		long long id, m1, s1, m2, s2, m3, s3, m4, s4;
		for (int i = 0; i < n; i++) {
			cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			result.emplace_back((m1 + m2 + m3 + m4) * 60 + s1 + s2 + s3 + s4, id);
		}
		sort(result.begin(), result.end());
		cout << result[0].second << endl;
		cout << result[1].second << endl;
		cout << result[n - 2].second << endl;
	}
}