#include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while (cin >> n && n){
        vector<pair<int, int>> v(n);
        rep(i, n){
            cin >> v[i].second;
            int t = 0;
            rep(j, 4){
                int m, s; cin >> m >> s;
                t += m * 60 + s;
            }
            v[i].first = t;
        }
        sort(v.begin(), v.end());
        cout << v[0].second << endl;
        cout << v[1].second << endl;
        cout << v[v.size() - 2].second << endl;
    }
}