#include <iostream>
#include <cstdlib>

using namespace std;

struct team{
	unsigned int time;
	unsigned int tm;
};

void func(team *a, int n)
{
	team t;
	for(int i = n-1; i >= 0; i--){
		for(int j = 1; j <= i; j++){
			if(a[j].time < a[j-1].time){
				t = a[j];
				a[j] = a[j-1];
				a[j-1] = t;
			}
		}
	}
	
	return ;
}

int main(int argc, char **argv)
{
	int n, m, s;
	team *a;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (team *)calloc(n, sizeof(team));
		
		for(int i = 0; i < n; i++){
			cin >> a[i].tm;
			for(int j = 0; j < 4; j++){
				cin >> m >> s;
				a[i].time += 60*m+s;
			}
		}
		func(a, n);
		
		cout << a[0].tm << endl << a[1].tm << endl << a[n-2].tm << endl;
		free(a);
	}
	
	return 0;
}