#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		pii good[3], bad[3];
		fill_n(good, 2, pii(3600, 0));
		fill_n(bad, 2, pii(0, 0));
		
		rep(i, n){
			pii team(0, 0);
			scanf("%d", &team.second);
			rep(j, 4){
				int m, s;
				scanf("%d%d", &m, &s);
				team.first += m * 60 + s;
			}
			good[2] = team;
			sort(good, good+3);
			bad[2] = team;
			sort(bad, bad+3, greater<pii>());
		}
		
		printf("%d\n", good[0].second);
		printf("%d\n", good[1].second);
		printf("%d\n", bad[1].second);
	}
	
	return 0;
}