#include <iostream>
#include <algorithm>

struct Team {
	int id;
	int time;
};
bool operator < (const Team& t1, const Team& t2) { return t1.time < t2.time; }

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		Team* teams = new Team[n];
		for (int i=0; i<n; i++) {
			int id, m1, s1, m2, s2, m3, s3, m4, s4;
			std::cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			teams[i].id = id;
			teams[i].time = 60*(m1+m2+m3+m4) + s1+s2+s3+s4; 
		}
		std::sort(teams, teams + n);
		std::cout << teams[0].id << std::endl;
		std::cout << teams[1].id << std::endl;
		std::cout << teams[n-2].id << std::endl;
		delete[] teams;
	}
	return 0;
}

