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

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vector< pair<int, int> > res;
        for (int i = 0; i < n; i++) {
            int team;
            int m1, s1, m2, s2, m3, s3, m4, s4;
            cin >> team >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            res.push_back(make_pair((m1+m2+m3+m4)*60+(s1+s2+s3+s4), team));
        }
        sort(res.begin(), res.end());
        cout << res[0].second << endl << res[1].second << endl << res[n-2].second << endl;
    }
    return 0;
}