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

struct Team{
    int id;
    int time;
    bool operator<(const Team& other)const{
        return time < other.time;
    }
};

int main(){
    int n, id, m, s, i, j;
    while(cin >> n, n){
        vector< Team > v(n);
        for(i = 0; i < n; i++){
            cin >> id;
            v[i].id = id;
            v[i].time = 0;
            for(j = 4;j--;){
                cin >> m >> s;
                v[i].time += m*60 + s;
            }
        }
        sort(v.begin(), v.end());
        cout << v[0].id << '\n' << v[1].id
             << '\n' << v[n-2].id << endl;
    }
    return 0;
}