#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(void)
{
	
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		int c1, m1, s1, m2, s2, m3, s3, m4, s4;
		vector< pair<int, int> >g;
		for (int i = 0; i < n; ++i){
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			g.push_back(make_pair(60 * (m1 + m2 + m3 + m4) + (s1 + s2 + s3 + s4), c1));
		}
		
		sort(g.begin(), g.end());
	
		cout << g[0].second << endl;
		cout << g[1].second << endl;	
		cout << g[n - 2].second	<< endl;
	}
	return 0;
}