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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<P> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i].second;
			int sum = 0;
			for(int j = 0; j < 8; ++j)
			{
				int temp;
				cin >> temp;
				if(j % 2 == 0)
				{
					sum += temp * 60;
				}
				else
				{
					sum += temp;
				}
			}
			Vec[i].first = sum;
		}
		sort(Vec.begin(), Vec.end());
		cout << Vec[0].second << endl;
		cout << Vec[1].second << endl;
		cout << Vec[n - 2].second << endl;
	}
}

int main()
{
	solve();
	return(0);
}