#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
#include<cstdio>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007

bool comp(const pair<string,int>& p,const pair<string,int>& q){
    return p.second > q.second;
  }

int main(){

    int n;
    while(cin >> n,n){

        
        vector<P> arr;
        int id,m1,s1,m2,s2,m3,s3,m4,s4;
        REP(i,n){
            int tmp = 0;
            cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            tmp = 60*m1 + s1 + 60*m2 + s2 +60*m3 + s3 +60*m4 + s4;
            arr.pb(make_pair(tmp,id));
        }
        VSORT(arr);
        cout << arr[0].second << endl;
        cout << arr[1].second << endl;
        cout << arr[arr.size()-2].second << endl;
    }

    return 0;
}

