#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
using namespace std;
typedef pair<int,int> P;

int main(){
    int n,i;
    while(cin>>n&&n){
        vector<P> ra;
        for(i=0;i<n;i++){
            int id,m1,m2,m3,m4,s1,s2,s3,s4;
            cin>>id>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
            int t=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
            P p(t,id);
            ra.push_back(p);
        }
        sort(ra.begin(),ra.end());
        cout<<ra[0].second<<endl;
        cout<<ra[1].second<<endl;
        cout<<ra[ra.size()-2].second<<endl;
    }
    return 0;
}
