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

typedef pair<int, int> P;

int n;
vector<P> ps;

int main()
{
    int c, m, s, sum;
    while(cin >> n && n) {
        ps.clear();
        for(int k = 0; k < n; k++) {
            cin >> c;
            sum = 0;
            for(int i = 0; i < 4; i++) {
                cin >> m >> s;
                sum += m * 60 + s;
            }
            ps.push_back(P(sum, c));
        }
        sort(ps.begin(), ps.end());
        
        cout << ps[0].second << endl;
        cout << ps[1].second << endl;
        cout << ps[ps.size() - 2].second << endl;

    }
    
}