#include <cstdio>
#include <vector>
#include <algorithm>

typedef struct {
	int id;
	int time;
} Team;

using namespace std;

bool operator < (const Team &a, const Team &b)
{
	return (a.time < b.time);
}

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		vector<Team> in(n);
		
		for (int i = 0; i < n; i++){
			int m, s;
			scanf("%d", &in[i].id);
			in[i].time = 0;
			for (int j = 0; j < 4; j++){
				scanf("%d %d", &m, &s);
				in[i].time += m * 60 + s;
			}
		}
		
		sort(in.begin(), in.end());
		
		printf("%d\n%d\n%d\n", in[0].id, in[1].id, in[n - 2].id);
	}
	
	return (0);
}