#include<stdio.h>
#include<string.h>

typedef struct{
	int no;
	int time;
}team;

team aki[1000000],t;
int n,a,b,i,j;

int main(){
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		memset(aki,0,sizeof(aki));
		
		for(i=0;i<n;i++){
			scanf("%d",&aki[i].no);
			for(j=0;j<4;j++){
				scanf("%d%d",&a,&b);
				aki[i].time+=60*a+b;
			}
		}
		
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				if(aki[i].time>aki[j].time){
					t=aki[j];
					aki[j]=aki[i];
					aki[i]=t;
				}
			}
		}
		printf("%d\n%d\n%d\n",aki[0].no,aki[1].no,aki[n-2].no);
	}
	return 0;
}