#include <bits/stdc++.h>
using namespace std;
void solve(int n){
	vector<pair<int,int> >v;
	for(int i;i<n;i++){
		int id;cin>>id;
		int cnt=0;
		for(int j=0;j<4;j++){int a,b;cin>>a>>b;cnt+=a*60+b;}
		v.push_back(make_pair(cnt,id));
	}
	sort(v.begin(),v.end());
	cout<<v[0].second<<endl;
	cout<<v[1].second<<endl;
	cout<<v[n-2].second<<endl;
	return;
}
int main() {
	int n;while(cin>>n){
		if(!n)return 0;
		solve(n);
	}
	return 0;
}