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

using namespace std;

int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;

        vector< pair<long long, int> > team;

        for (int i = 0; i < n; i++) {
            int id;
            long long time;
            int m, s;

            time = 0;
            cin >> id;
            for (int j = 0; j < 4; j++) {
                cin >> m >> s;
                time += m * 60 + s;
            }
            team.push_back(pair<long long, int>(time, id));
        }
        sort(team.begin(), team.end());

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

    return 0;
}