#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef pair<int,int> P;
int main(){
  P p;
  vector<P> ar;
  int n,c1,m1,s1,m2,s2,m3,s3,m4,s4;
  while(1){
    cin >> n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      p.first = ((m1 + m2 + m3 + m4)*60) + (s1+s2+s3+s4);
      p.second = c1;
      ar.push_back( p );
    }
    sort( ar.begin() , ar.end() );
    cout << ar[0].second << endl;
    cout << ar[1].second << endl; 
    cout << ar[n-2].second << endl;
    ar.clear();
  }
}