#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

int main(){
	int n;
	while( cin >> n , n ){
		vector<P> vc;

		for(int i=0 ; i < n ; i++ ){
			int c,m1,m2,m3,m4,s1,s2,s3,s4;
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int time = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
			P p( time , c );
			vc.push_back( p );
		}
		sort( vc.begin() , vc.end() );
		cout << vc[0].second << endl;
		cout << vc[1].second << endl;
		cout << vc[vc.size()-2].second << endl;
	}
}