#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		vector<pair<int,int> > d;
		rep(i,0,n){
			int name,m,s,sum=0;
			cin>>name;
			rep(i,0,4){
				cin>>m>>s;
				sum+=60*m+s;
			}
			d.push_back(make_pair(sum,name));
		}
		sort(all(d));
		o(d[0].second);
		o(d[1].second);
		o(d[n-2].second);
	}
}