#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<sstream>

#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)
#define PP pair< int,PII >
#define Sort(t) sort(t.begin(), t.end())

using namespace std;
typedef pair<int,int> PII;

priority_queue<PII,vector< PII > , greater< PII > > pq;

int main(void){
	int n;
	while(scanf("%d", &n),n){
		rep(i,n){
			int id;
			cin >> id;
			int sum = 0, x;
			rep(j,8){
				cin >> x;
				sum += j%2==0?x*60:x;
			}
			pq.push( pair<int,int>(sum,id));
		}
		/*
		while(!pq.empty()){
			printf("%d %d\n",pq.top().first, pq.top().second);
			pq.pop();
		}*/
		printf("%d\n", pq.top().second);pq.pop();
		printf("%d\n", pq.top().second);pq.pop();
		while(pq.size() > 2)pq.pop();
		printf("%d\n", pq.top().second);pq.pop();
		pq.pop();
	}
	
	return 0;
}