#include<cstdio>
#define buf 100000
using namespace std;

typedef struct{
	int s,m;
}Sport;
void BubbleSort(int n);
int B[buf];

int main(void){
	Sport t,b,g,r;
	int i,k,n,z,sum,A[buf];
	char str[1000];

	for( ; ; ){
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d",&n);
		if(n==0) break; k=0; sum=0;
		for(i=0;i<n;i++){
			fgets(str,sizeof(str),stdin);
			sscanf(str,"%d %d %d %d %d %d %d %d %d",&z,&t.m,&t.s,&b.m,&b.s,&g.m,&g.s,&r.m,&r.s);
			sum=(t.m*60)+t.s+(b.m*60)+b.s+(g.m*60)+g.s+(r.m*60)+r.s;
			A[sum]=z; B[k]=sum; k++;
		}
		BubbleSort(n);
		printf("%d\n%d\n%d\n",A[B[0]],A[B[1]],A[B[n-2]]);
	}
	return 0;
}

void BubbleSort(int n){
	int i,j,tmp;
	for(i=0;i<n-1;i++){
		for(j=n-1;j>i;j--){	
			if(B[j] < B[j-1]){
				tmp = B[j-1];
				B[j-1] = B[j];
				B[j] = tmp;
			}
		}
	}
}