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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

typedef pair<int, int> pp;

int main()
{
    int n, c, m[4], s[4], sum[4];

    while(cin >> n && n)
    {
        vector<pp> res;
        REP(n)
        {
            cin >> c;
            rep(j,4)cin>> m[j] >> s[j]; 
            res.push_back(pp((m[0]+m[1]+m[2]+m[3])*60 + s[0]+s[1]+s[2]+s[3], c));
        }
        sort(all(res));
        cout << res[0].second << endl;
        cout << res[1].second << endl;
        cout << res[n-2].second << endl;
    }

    return 0;
}