#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		vector<pair<int,int> > data;
		int c1,m1,m2,m3,m4,s1,s2,s3,s4;
		while(n--){
			cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
			int sum=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
			data.push_back(make_pair(sum,c1));
		}
		sort(data.begin(),data.end());
		cout<<data[0].second<<endl;
		cout<<data[1].second<<endl;
		cout<<data[data.size()-2].second<<endl;
	}
}