#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
typedef struct{
    int id;
    pii n,n2,n3,n4;
    int sum=0;
}data;
int main(){
    int n;
    while(cin>>n,n){
    vector<data>u(n);
    rep(i,n){
        pii n, n2,n3,n4;int id;
        cin>>id>>n.first>>n.second>>n2.first>>n2.second>>n3.first>>n3.second>>n4.first>>n4.second;
        u[i].id=id;
        u[i].n=n;u[i].n2=n2;u[i].n3=n3;u[i].n4=n4;
        u[i].sum=(n.first+n2.first+n3.first+n4.first)*60+(n.second+n2.second+n3.second+n4.second);
    }
    rep(i,n-1)rep(j,n-1)if(u[j].sum>u[j+1].sum)swap(u[j],u[j+1]);
    rep(i,2)cout<<u[i].id<<endl;
    cout<<u[n-2].id<<endl;
    }
}