#include<iostream>
using namespace std;
int main(){
	int n,u1,u2,s1,s2,U1,U2,S1,S2
	,c,a,b,r,d,e,f,g,h,k,x,y,ren,temp;
	while(cin>>n,n){
		u1=100000000;
		u2=100000000;
		s1=0;
		s2=0;
		for(int i=0;i<n;i++){
			cin>>r>>a>>b>>c>>d>>e>>f>>g>>h;
			x=(a+c+e+g)*60+b+d+f+h;
			y=x;
			k=r;
			if(u1>x){
				ren=U1;
				U1=r;
				r=ren;
				temp=u1;
				u1=x;
				x=temp;
			}
			if(u2>x){
				U2=r;
				u2=x;
			}
			if(s1<y){
				ren=S1;
				S1=k;
				k=ren;
				temp=s1;
				s1=y;
				y=temp;
			}
			if(s2<y){
				S2=k;
				s2=y;
			}
		}
		
		cout<<U1<<endl<<U2<<endl<<S2<<endl;
		
		
	}
	return 0;
}