#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int>P;
int main(){
    int n;
    while(cin>>n,n){
        vector<P>V(n);
        for(int i=0;i<n;i++){
            cin>>V[i].second;
            V[i].first=0;
            for(int i=0;i<4;i++){
                int a,b;
                cin>>a>>b;
                V[i].first+=a*60+b;
            }
        }
        sort(V.begin(),V.end());
        cout<<V[0].second<<endl;
        cout<<V[1].second<<endl;
        cout<<V[n-2].second<<endl;
    }
    return 0;
}