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

int main()
{
	int a, time, number, m1, s1, m2, s2, m3, s3, m4, s4;
	vector<pair <int, int> > team;
	
	while(1)
	{
		cin >> a;
		if (a == 0)
		{
			break;
		}
		team.clear();
		for(int i = 0; i < a; i++)
		{
			cin >> number;
			cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			time = m1 *60  + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
		
			team. push_back(make_pair(time, number));
		
		}
	
		sort(team.begin(), team.end());
	
		cout << team[0].second << endl;
		cout << team[1].second << endl;
		cout << team[a - 2].second << endl;
	}
	return 0;
}