#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int n;
int w[1000];
int v[1000];

int dp[1000][1000];
int rec(int i, int j){
	if (dp[i][j]>0) return dp[i][j];
		int res;
	if (i == n) res = 0;
	else if (j<w[i]){
		res = rec(i + 1, j);
	}
	else{
		res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);
	}
	dp[i][j] = res;
	return res;
}

int main(int argc, char **argv){
	int n;
	while (cin >> n && n > 0) {
		pair<int, int> p;
		vector<pair<pair<int, int>, int>> v;
		int ci;
		int m, s;
		for (int i = 0; i < n; i++) {
			cin >> ci;
			p.first = 0;
			p.second = 0;
			for (int j = 0; j < 4; j++) {
				cin >> m >> s;
				p.first += m;
				p.second += s;
			}
			p.first += p.second / 60;
			p.second %= 60;
			v.push_back(make_pair(p, ci));
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl;
		cout << v[1].second << endl;
		cout << v[v.size() - 2].second << endl;
	}
	return 0;
}