#include <stdio.h>
#include <algorithm>
using namespace std;
const int N=1e5+10;
struct t{
    int m;
    int s;
    void operator +=(const t &a){
        m+=a.m;
        s+=a.s;
        pull();
        return ;
    }
    void pull(){
        m+=s/60;
        s%=60;
        return ;
    }
    void in(){
        scanf("%d%d",&m,&s);
        return ;
    }
};
t a[N];
int f[N];
bool cmp(const int &l,const int &r){return a[l].m==a[r].m?a[l].s<a[r].s:a[l].m<a[r].m;}
int main(){
    int n,s[N];
    t temp;
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            scanf("%d",&s[i]);
            f[i]=i;
            a[i].in();
            for(int j=0;j<3;j++){
                temp.in();
                a[i]+=temp;
            }
        }
        sort(f,f+n,cmp);
        printf("%d\n%d\n%d\n",s[f[0]],s[f[1]],s[f[n-2]]);
    }
}
