//01/12/miya
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
while(true){
	int n;
	cin >> n;

	if(n==0)break;

	int c[1000000],t[1000000];
	for(int i=0;i<n;i++){		
		int m1,s1,m2,s2,m3,s3,m4,s4;
		cin >> c[i];
		cin >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
		t[i] = m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4;
	}
	for(int i=0;i<n;i++){
		for (int j=n-1;j>i;j--){
			if(t[j]<t[j-1]){
				swap(t[j],t[j-1]);
				swap(c[j],c[j-1]);
			}
		}
	}
	cout << c[0] << endl << c[1] << endl << c[n-2] << endl;
}
return 0;
}