#include <iostream>
#include <vector>
#include <algorithm>
struct team{
  int n;
  int ti;
};

bool ascending_time_team(const team& _t1,const team& _t2){
  return _t1.ti<_t2.ti;
}
int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    std::vector<team> v;
    for(int i=0;i<n;i++){
    int c1,m[4],s[4];
    std::cin>>c1>>m[0]>>s[0]>>m[1]>>s[1]>>m[2]>>s[2]>>m[3]>>s[3];
    int tsec=0;
    for(int i=0;i<4;i++)
      tsec+=m[i]*60+s[i];
    team t;
    t.n=c1;
    t.ti=tsec;
    v.push_back(t);
    }
    std::sort(v.begin(),v.end(),ascending_time_team);
    std::cout<<v[0].n<<"\n"<<v[1].n<<"\n"<<v[v.size()-2].n<<"\n";
  }
}