#include <bits/stdc++.h>

typedef std::pair< unsigned int, unsigned int > P;

unsigned int n;

int main() {
    unsigned int id;
    unsigned int m, s;
    while ( std::cin >> n, n ) {
        std::vector< P > vec;
        for (int i=0; i<n; ++i) {
            unsigned int time = 0;
            std::cin >> id;
            for (int j=0; j<4; ++j) {
                std::cin >> m >> s;
                time += m*60 + s;
            }
            vec.push_back( std::make_pair( time, id ) );
        }
        std::sort( vec.begin(), vec.end() );
        // std::vector< P >::iterator itr=vec.begin();
        std::cout << vec[0].second << '\n'
                  << vec[1].second << '\n'
                  << vec[n-2].second
                  << std::endl;
    }
    return 0;
}

