#include <iostream>
#include <algorithm>

using namespace std;

struct Team {
	int num;
	int min[4];
	int s[4];
	int total;
};

int compute(Team group);
bool compare(Team i, Team j) {
	return (i.total < j.total);
}

int main() {

	int n;
	while (cin >> n && n != 0) {

		Team *group = new Team[n];

		for (int i = 0; i < n; i++) {

			cin >> group[i].num;

			for (int j = 0; j < 4; j++)
				cin >> group[i].min[j] >> group[i].s[j];

			group[i].total = compute(group[i]);
		}

		sort(group, group + n, compare);
		cout << group[0].num << "\n"
			 << group[1].num << "\n"
			 << group[n - 2].num<< "\n";
	}

	

	return 0;

}

int compute(Team group) {

	int total = 0;
	for (int i = 0; i < 4; i++)
		total += (group.min[i] * 60 + group.s[i]);

	return total;
}


