#include <iostream>
#include <vector>
#include <algorithm>
struct team{
  int num;
  int time;
};

bool ascending_time_team(const team& _t1,const team& _t2){
  return _t1.time<_t2.time;
}
int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    std::vector<team> v;
    /*
    //Å¬AñÔèAu[r[Ì`[ÔAÔðÛ·éB
    int fteam=0,fsec=0,steam=0,ssec=0,bteam=0,bsec=0;
    */
    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;//êIÉg¢Ü·B
    for(int i=0;i<4;i++){
      tsec+=m[i]*60+s[i];
    }
    team t;
    t.num=c1;
    t.time=tsec;
    v.push_back(t);
    }
    std::sort(v.begin(),v.end(),ascending_time_team);
    std::cout<<v[0].num<<std::endl<<v[1].num<<std::endl<<v[v.size()-2].num<<std::endl;
  }
}
/*
Sample Input
8
34001 3 20 3 8 6 27 2 25
20941 3 5 2 41 7 19 2 42
90585 4 8 3 12 6 46 2 34
92201 3 28 2 47 6 37 2 58
10001 3 50 2 42 7 12 2 54
63812 4 11 3 11 6 53 2 22
54092 3 33 2 54 6 18 2 19
25012 3 44 2 58 6 45 2 46
4
1 3 23 1 23 1 34 4 44
2 5 12 2 12 3 41 2 29
3 5 24 1 24 2 0 3 35
4 4 49 2 22 4 41 4 23
0
Output for the Sample Input
54092
34001
10001
1
3
2
*/