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

bool ope(const pair<int,int>&left, const pair<int,int>&right){
	return left.second < right.second;
}

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