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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int n;
int id[100005], m[100005][4], s[100005][4];
void solve() {
    vector<pair<int, int>> vec;
    rep(i, n) {
        int sum = 0;
        rep(j, 4) sum += m[i][j] * 60 + s[i][j];
        vec.emplace_back(sum, id[i]);
    }
    sort(vec.begin(), vec.end());
    cout << vec[0].second << endl;
    cout << vec[1].second << endl;
    cout << vec[n - 2].second << endl;
}
int main() {
    while (cin >> n, n) {
        rep(i, n) {
            cin >> id[i];
            cin >> m[i][0] >> s[i][0];
            cin >> m[i][1] >> s[i][1];
            cin >> m[i][2] >> s[i][2];
            cin >> m[i][3] >> s[i][3];
        }
        solve();
    }
}