#include <map>
#include <iostream>

using namespace std;

int main()
{
	int n;

	while (cin >> n, n){
		map<int, int> team;
		int id, m1, m2, m3, m4, s1, s2, s3, s4;
		for (int i = 0; i < n; i++){
			cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			team.insert(make_pair(60 * (m1 + m2 + m3 + m4) + s1 + s2 + s3 + s4, id));
		}
		map<int, int>::iterator it = team.begin();
		cout << it->second << endl;
		it++;
		cout << it->second << endl;
		it = team.end();
		it--;
		it--;
		cout << it-> second << endl;
	}

	return (0);
}