#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

typedef struct{
    int num;
    int sum;
} teams;

void q_sort(teams data[], int begin, int end);

int main(int argc, const char * argv[])
{
    int num = 0;
    while (1) {
        scanf("%d", &num);
        if (num == 0) {
            break;
        }
        teams data[1000000];
        int m[4], s[4];
        for (int i = 0; i < num; i++) {
            data[i].sum = 0;
            scanf("%d %d %d %d %d %d %d %d %d", &data[i].num, &m[0], &s[0], &m[1], &s[1], &m[2], &s[2], &m[3], &s[3]);
            for (int k = 0; k < 4; k++) {
                data[i].sum += m[k] * 60 + s[k];
            }
        }
        q_sort(data, 0, num - 1);
        for (int i = 0; i < 2; i++) {
            printf("%d\n", data[i].num);
        }
        printf("%d\n", data[num - 2].num);
    }
    return 0;
}

void q_sort(teams data[], int begin, int end){
    int i = begin;
    int k = end;
    teams pivot = data[(begin + end) / 2];
    teams temp;
    while (1) {
        while (data[i].sum < pivot.sum) {
            i++;
        }
        while (pivot.sum < data[k].sum) {
            k--;
        }
        if (i >= k) {
            break;
        }
        temp = data[i];
        data[i] = data[k];
        data[k] = temp;
        i++;
        k--;
    }
    if (begin < i - 1) {
        q_sort(data, begin, i - 1);
    }
    if (k + 1 < end) {
        q_sort(data, k + 1, end);
    }
}