#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct data{
    int key;
    int time;
};

int main(){
    int n;
    while(cin >> n, n){
        struct data d[1000005];
        rep(i,n){
            int key, m1, s1, m2, s2, m3, s3, m4, s4;
            cin >> d[i].key >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            d[i].time = (m1 + m2 + m3 + m4) * 60 + s1 + s2 + s3 + s4;
        }
        rep(i,n){
            for(int j = n - 1; j > i; j--){
                if(d[j].time < d[j - 1].time){
                    struct data g = d[j];
                    d[j] = d[j - 1];
                    d[j - 1] = g;
                }
            }
        }
        cout << d[0].key << endl << d[1].key << endl << d[n - 2].key << endl;
    }
}