#include <iostream>
#include <map>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		map<int,int> data;
		for(int i=0,num;i<n;++i){
			int sum=0;
			cin>>num;
			for(int j=0,m,s;j<4;++j){
				cin>>m>>s;
				sum+=m*60+s;
			}
			data.insert(map<int,int>::value_type(sum,num));
		}
		map<int,int>::iterator it = data.begin();
		cout<<(*it).second<<"\n";
		++it;
		cout<<(*it).second<<"\n";
		map<int,int>::reverse_iterator rit = data.rbegin();
		++rit;
		cout<<(*rit).second<<"\n";
	}
	return 0;
}