#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int solve_testcase() {
    int N; cin >> N;
    if(N == 0) return 1;

    vector< pair<int, int> > info;
    for(int i=0; i<N; i++) {
        int id; cin >> id;
        int sum = 0;
        for(int k=0; k<4; k++) {
            int m, s; cin >> m >> s;
            int total_time = m * 60 + s;
            sum += total_time;
        }
        info.emplace_back(sum, id);
    }

    sort(info.begin(), info.end());
    cout << info[0].second << endl;
    cout << info[1].second << endl;
    cout << info[N-2].second << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}

