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

typedef vector <int> VI;

int main( void )
{
	int n, no, mm, ss;
	while ( cin >> n && n )
	{
		VI no_list( n );
		VI time_list( n );

		for ( int j = 0; j < n; j++ )
		{
			cin >> no;
			int sum = 0;
			for ( int i = 0; i < 4; i++ )
			{
				cin >> mm >> ss;
				ss += mm * 60;
				sum += ss;
			}
			no_list[j] = no;
			time_list[j] = sum;
		}

		for ( int i = 0; i < n-1; i++ )
		{
			for ( int j = i+1; j < n; j++ )
			{
				if ( time_list[i] > time_list[j] )
				{
					swap( time_list[i], time_list[j] );
					swap( no_list[i], no_list[j] );
				}
			}
		}

		cout << no_list[0] << endl;
		cout << no_list[1] << endl;
		cout << no_list[n-2] << endl;
	}
	return 0;
}