#include <iostream>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

int main(void)
{
	vector< pair<unsigned long,unsigned long> > team;

	unsigned long n;

	while( cin >> n && n != 0 ){
		team.clear();
		for( long i = 0;i < n;i++ ){
			unsigned long sum = 0;;
			unsigned long m,s;
			unsigned long number;

			cin >> number;

			for( long j = 0;j < 4;j++ ){
				cin >> m >> s;
				sum += m * 60 + s;
			}
			team.push_back( pair<unsigned long, unsigned long>( sum, number ) );
		}

		sort( team.begin(), team.end() );

		for( long i = 0;i < 2;i++ ){
			cout << team[i].second << endl;
		}
		cout << team[n - 2].second << endl;
	}

	return 0;
}