#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n,a[100000],b[100000],m,s;
	
	while(1){
		cin >> n  ;
		if(n==0){
			return 0;
		}
		for(int i=0;i<n;i++){
			cin >> a[i] ;
			b[i]=0;
			for(int j=0;j<4;j++){
				cin >> m >>s ;
				b[i]+=60*m+s;
			}
		}
		for(int i=1;i<n;i++){
			for(int j=0;j<n-i;j++){
				if(b[j]<b[j+1]){
					m=b[i]; b[i]=b[i+1]; b[i+1]=m;
					s=a[i]; a[i]=a[i+1]; a[i+1]=s;
				}
			}
		}
		
		cout << a[0] << "\n" << a[1] << "\n" << a[n-2] << "\n" ;
	}
	
return 0;
}