#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool func(pair< int, int > a, pair< int, int > b){
	return a.second < b.second;
}

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