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

int main(){
	while(true){
		int n;
	       cin >> n;
		if(n==0)
			break;

		int *tn=new int[n];
		int *tt1=new int[n];
		int *tt2=new int[n];

		for(int i=0; i<n; i++){
			tt1[i]=0;	
			tt2[i]=0;		
		}

		for(int i=0; i<n; i++){
			cin >> tn[i];
			for(int j=0; j<4; j++){
				int m,s;
				cin >> m >> s;
				tt1[i]=tt1[i]+60*m+s;
				tt2[i]=tt2[i]+60*m+s;
			}
		}
		
		stable_sort(tt1,tt1+n);

		int a,b,c;

		for(int i=0; i<n;i++){
			if(tt2[i]==tt1[0]){
				a=tn[i];
				break;
			}
		}
		for(int i=0; i<n;i++){
			if(tt2[i]==tt1[1]){
				b=tn[i];
				break;
			}
		}
		for(int i=0; i<n;i++){
			if(tt2[i]==tt1[n-2]){
				c=tn[i];
				break;
			}
		}
		
		cout << a << endl << b << endl << c << endl;

		delete[] tn;
		delete[] tt1;
		delete[] tt2;
	}
		

}