#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	while(1){
		int n=0;
		int c[100001];
		int m1[100001];
		int m2[100001];
		int m3[100001];
		int m4[100001];

		int s1[100001];
		int s2[100001];
		int s3[100001];
		int s4[100001];

		int A[100001];
		int Ad[100001];

		int A1=0;
		int A2=0;
		int Ab=0;

		cin>>n;
		if(n==0){
			break;
		}
	
		for(int i=0;n>i;i++){
			cin>>c[i];
			cin>>m1[i];
			cin>>s1[i];
			cin>>m2[i];
			cin>>s2[i];
			cin>>m3[i];
			cin>>s3[i];
			cin>>m4[i];
			cin>>s4[i];
			m1[i]=60*m1[i];
			m2[i]=60*m2[i];
			m3[i]=60*m3[i];
			m4[i]=60*m4[i];
			A[i]=m1[i]
			+m2[i]
			+m3[i]
			+m4[i]
			+s1[i]
			+s2[i]
			+s3[i]
			+s4[i];
			Ad[i]=m1[i]
			+m2[i]
			+m3[i]
			+m4[i]
			+s1[i]
			+s2[i]
			+s3[i]
			+s4[i];
		}
		sort(A,A+n);
		
		for(int i=0;n>i;i++){
			if(A[0]==Ad[i]){
				A1=c[i];
			}
			if(A[1]==Ad[i]){
				A2=c[i];
			}
			if(A[n-2]==Ad[i]){
				Ab=c[i];
			}
		}
		cout<<A1<<endl;
		cout<<A2<<endl;
		cout<<Ab<<endl;
		
}
return 0;
}