#include <stdio.h>
#include <string>
#include <algorithm>

using namespace std;

struct team {
    int number;
    int time;
};

typedef struct team Team;
bool tfsort (const team &a, const team &b);

int main(){
    int i, n=1,time, times, second, a, b, c, d, e, f, g, h;
    Team rec[10];
    int number[1000001],team[1000001];
    
    for (;n>0;n--){
        scanf("%d",&n);
//        printf("%d\n",n);
        for(i = 0; i < n; i++){
            scanf("%d %d %d %d %d %d %d %d %d", &number[i], &a, &b, &c, &d, &e, &f, &g, &h);
            times = (b+d+f+h);
            time = times / 60;
            second = times - time * 60;
            team[i] = (a+c+e+g+time)*100 + second;
            rec[i] = (Team){number[i], team[i]};
        }
        sort(rec, rec + n, tfsort);
        
        for(i = 0; i < 2; i++){
            printf("%d\n", rec[i].number);
        }
        printf("%d\n", rec[n -2].number);
    }
    return 0;
}

bool tfsort (const team &a, const team &b){
    if(a.time < b.time) return true;
    return false;
}