//08
#include<iostream>
#include<utility>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    static pair<int,int> a[1000000];
    for(int i=0;i<n;i++){
      int c;
      cin>>c;
      int t=0;
      for(int j=0;j<4;j++){
	int m,s;
	cin>>m>>s;
	t+=m*60+s;
      }
      a[i]=make_pair(t,c);
    }
    sort(a,a+n);
    cout<<a[0].second<<endl;
    cout<<a[1].second<<endl;
    cout<<a[n-2].second<<endl;
  }
  return 0;
}