#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> P;
P sum[1000001];
int N;
main(){
  while(1){
    scanf("%d",&N);
    if(!N) break;
    for(int i=0;i<N;i++){
      int c;
      scanf("%d",&c);
      sum[i].first=0;
      sum[i].second=c;
      for(int j=0;j<4;j++){
	int m,s;
	scanf("%d %d",&m,&s);
	sum[i].first += m*60+s;
      } 
    }
    sort(sum,sum+N);
    printf("%d\n%d\n%d\n",sum[0].second,sum[1].second,sum[N-2].second);
  }
}