#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#define swap(type, x, y) do{type temp = x; x = y; y = temp;}while(0);
using namespace std;

typedef struct {
    long long int num;
    int min[4] = {0};
    int sec[4] = {0};
    int sum = 0;
}team;

void quick_sort(team x[], int left, int right);

int main(void) {
    int n;
    
    while(1) {
        scanf("%d", &n);
        if(n == 0) break;
        int i, j;
        team *p;
        p = (team *)calloc(n, sizeof(team));
        if(p == NULL) exit(0);
        
        for(i = 0; i < n; i++) {
            scanf("%lld", &p[i].num);
            for(j = 0; j < 4; j++)
                scanf("%d %d", &p[i].min[j] , &p[i].sec[j]);
        }
        for(i = 0; i < n; i++) {
            for(j = 0; j < 4; j++)
                p[i].sum += (p[i].min[j] * 60) + p[i].sec[j];
        }
        quick_sort(p, 0, n - 1);
        
        cout << p[0].num << endl << p[1].num << endl << p[n - 2].num << endl;
        free(p);
    }
    
    return(0);
}

void quick_sort(team x[], int left, int right) {
    int i, j;
    team pivot;
    
    i = left;
    j = right;
    pivot.sum += x[(left + right) / 2].sum;
    
    while(1) {
        while(x[i].sum < pivot.sum) i++;
        while(x[j].sum > pivot.sum) j--;
        
        if(i >= j) break;
        
        swap(team, x[i], x[j]);
        i++;
        j--;
        // DEBUG cout << "OK" << endl;     ここの時点では出力に”OK”と沢山表示される
    }
    
    if(i - 1 > left) quick_sort(x, left, i - 1);
    if(j + 1 < right) quick_sort(x, j + 1, right);
}