#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

void solve(int n){
    vector<pair<int,int> > v;
    for(int i=0;i<n;i++){
        int c;int t=0;
        cin >> c;
        for(int j=0;j<4;j++){
            int m,s;
            cin >> m >> s;
            t += 60*m + s;
        }
        v.push_back(make_pair(t,c));
    }
    sort(v.begin(),v.end());
    cout << v[0].second << endl;
    cout << v[1].second << endl;
    cout << v[v.size()-2].second << endl;
}

int main(){
    int n;
    while(cin >> n && n != 0){
        solve(n);
    }
}