#include<algorithm>
#include<iostream>
#include<utility>
#include<vector>

typedef std::pair<int, int> P;

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		std::vector<P> v;

		while( n-- )
		{
			int c, t = 0;
			
			std::cin >> c;
			for( int i = 0; i != 4; ++i )
			{
				int m, s;
				std::cin >> m >> s;
				t += m * 60 + s;
			}

			v.push_back( P( t, c ) );
		}

		std::sort( v.begin(), v.end() );

		for( int i = 0; i != 2; ++i )
			std::cout << v[i].second << std::endl;

		std::cout << v[v.size()-2].second << std::endl;
	}

	return 0;
}