#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

typedef pair<long long,string> p;

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		vector< p > vec(n);
		rep(i,n){
			long long timeh[4],timem[4],time=0;
			string num;
			cin>>num;
			rep(j,4){
				cin>>timeh[j]>>timem[j];
				time+=(timeh[j]*60+timem[j]);
			}
			vec[i].first=time;
			vec[i].second=num;
		}
		sort(vec.begin(),vec.end());
		cout<<vec[0].second<<endl;
		cout<<vec[1].second<<endl;
		cout<<vec[n-2].second<<endl;
	}
	return 0;
}