#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

class Time{
public:
	int id,score;
	Time(int _id,int _score){
		id = _id;
		score = _score;
	}
	bool operator<(const Time &t)const{
		return score < t.score;
	}
};

int main(void){
	int n;
	while(cin>>n,n){
			vector<Time> v;
		for(int i=0;i<n;i++){
			int id;
			cin>>id;
			int sum = 0;
			for(int j=0;j<4;j++){
				int x,y;
				cin>>x>>y;
				sum += x * 60 + y;
			}
			v.push_back(Time(id,sum));
		}
		sort(v.begin(),v.end());
		cout<<v[0].id<<endl;
		cout<<v[1].id<<endl;
		cout<<v[v.size()-2].id<<endl;
	}

	return 0;
}