#include<iostream>
#include<queue>

using namespace std;
class Team{
public:
	int id;
	int time;
	Team(int _id,int _time){
		id=_id;time=_time;
	}
	bool operator < (const Team &o) const{
		return time > o.time;
	}
};
typedef priority_queue<Team> PQ;
int n,c,m,s;
int main(){
	while(cin>>n&&n){
		PQ pq;
		for(int i=0;i<n;i++){
			int sum=0;
			cin>>c;
			for(int j=0;j<4;j++){
				cin>>m>>s;
				sum+=(m*60) + s;
			}

			pq.push(Team(c,sum));
		}
		cout<<pq.top().id<<endl;pq.pop();
		cout<<pq.top().id<<endl;pq.pop();
		while(pq.size()>2){
			pq.pop();
		}
		cout<<pq.top().id<<endl;pq.pop();
	}
	return 0;
}