#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;
ll are=1000000007;

int main() {
    while  (true){
        int n;
        cin >> n;
        if (n==0) break;
        vector<pp> a(n);
        rep(i,n){
            a.at(i).first=0;
            int u=0,y=0;
            cin >> a.at(i).second;
            rep(j,4){
                cin >> u >> y;
                a.at(i).first+=u*60+y;
            }
        }
        sort(a.begin(),a.end());
        cout << a.at(0).second << endl << a.at(1).second << endl <<  a.at(n-2).second << endl;
    }
}

