#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct Team{
	int id;
	int result;
	bool operator<(const Team &t)const{return result<t.result;}
};
void Input(Team &t){
	int c,m1,s1,m2,s2,m3,s3,m4,s4;
	scanf("%d%d%d%d%d%d%d%d%d",&c,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
	t.id = c;
	t.result = m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4;
}
int main(){
	while(true){
		int n;
		vector<Team> vteams;
		scanf("%d", &n);
		if(n==0)break;
		vteams.resize(n);
		for(int i = 0; i < n; ++i){Input(vteams[i]);}
		sort(vteams.begin(),vteams.end());
		printf("%d\n%d\n%d\n",vteams[0].id,vteams[1].id,vteams[n-2].id);
	}
	return 0;
}