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

using namespace std;

int main()
{
	vector<pair<int, int> > team;
	int n, min[4], sec[4], Sec, name;
	
	while(1){
		cin >> n;

		if(n == 0)    break;

		for (int i = 0; i < n; i++){
			cin >> name;

			cin >> min[0] >> sec[0] >> min[1] >> sec[1] >> min[2] >> sec[2] >> min[3] >> sec[3];

			Sec = 0;

			for (int j = 0; j < 4; j++){
				Sec += ((min[j] * 60) + sec[j]);
			}

			team.push_back(make_pair(Sec, name));
		}

		sort(team.begin(), team.end());

		cout << team[0].second << endl << team[1].second << endl << team[n-2].second << endl;
	
		team.clear();
	}

	return 0;
}