#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int a,b,c,d;
	int aa,bb,cc,dd;
	int n;
	while(n=in()){
		int i;
		aa=bb=0;
		cc=dd=100000000;
		int num;
		for(i=0;i<n;i++){
			cin>>num;
			int m,s;
			int j;
			int sum=0;
			for(j=0;j<4;j++){
				cin>>m>>s;
				sum+=m*60+s;
			}
//cout<<num<<" "<<sum<<endl;
			if(sum>aa){
				b=a;bb=aa;
				a=num;aa=sum;
			}else if(sum>bb){
				b=num;bb=sum;
			}
			if(sum<dd){
				c=d;cc=dd;
				d=num;dd=sum;
			}else if(sum<cc){
				c=num;cc=sum;
			}
//cout<<"a "<<a<<" "<<aa<<endl;
//cout<<"b "<<b<<" "<<bb<<endl;
//cout<<"c "<<c<<" "<<cc<<endl;
//cout<<"d "<<d<<" "<<dd<<endl;
		}
		cout<<d<<endl<<c<<endl<<b<<endl;
	}
	return 0;
}