#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;

int main() {
    int n;
    while(cin >> n, n) {
        vector<pii> scores;
        for(int i = 0; i < n; ++i) {
            int id; cin >> id;
            int t = 0;
            for(int j = 0; j < 4; ++j) {
                int m, s; cin >> m >> s;
                t += m * 60 + s;
            }
            scores.emplace_back(t, id);
        }
        sort(begin(scores), end(scores));

        cout << scores[0].second << endl;
        cout << scores[1].second << endl;
        cout << scores[n - 2].second << endl;
    }
}

