#include <iostream>
using namespace std;

struct Team {
    int num;
    int time;
};

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        Team team[] = {
            {0, 100000, },
            {0, 100000, },
            {0, 0, },
            {0, 0, },
        };
        for (int i = 0; i < n; i++) {
            int c, m[4], s[4];
            cin >> c;
            for (int j = 0; j < 4; j++) {
                cin >> m[j] >> s[j];
            }
            int time = 0;
            for (int j = 0; j < 4; j++) {
                time += m[j] * 60 + s[j];
            }
            if (time < team[0].time) {
                team[1].num = team[0].num;
                team[1].time = team[0].time;
                team[0].num = c;
                team[0].time = time;
            } else if (time < team[1].time) {
                team[1].num = c;
                team[1].time = time;
            }
            if (team[3].time < time) {
                team[2].num = team[3].num;
                team[2].time = team[3].time;
                team[3].num = c;
                team[3].time = time;
            } else if (team[2].time < time) {
                team[2].num = c;
                team[2].time = time;
            }
        }
        for (int i = 0; i < 3; i++) {
            cout << team[i].num << endl;
        }
    }
}