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

int main() {
    int n;
    while (cin >> n, n) {
        int c1,m1,s1,m2,s2,m3,s3,m4,s4;
        vector<pair<int,int> > data;
        for (int i=0; i<n; ++i) {
            cin>>c1>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
            data.push_back(make_pair((m1+m2+m3+m4)*60+(s1+s2+s3+s4),c1));
        }
        sort(data.begin(), data.end());
        cout << data[0].second << endl;
        cout << data[1].second << endl;
        cout << data[data.size()-2].second << endl;
    }
    return 0;
}