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

int main()
{
	int n;

	while( cin >> n && n ){
		vector< pair< int, int > > list;
		for( int i = 0; i < n; ++i ){
			int id, m, s, time = 0;
			cin >> id;
			for( int j = 0; j < 4; ++j ){
				cin >> m >> s;
				time += ( m * 60 + s );
			}
			list.push_back( make_pair( time, id ) );
		}
		sort( list.begin(), list.end() );

		cout << list[ 0 ].second << endl;
		cout << list[ 1 ].second << endl;
		cout << list[ list.size() - 2 ].second << endl;
	}

	return 0;
}