#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main(){

    int n;
    while(cin>>n,n){
        map < int , int > a;

        for(int i=0;i<n;i++){
            int t;
            cin>>t;
            int z=0;
            for(int j=0;j<4;j++){
                int x,y;
                cin>>x>>y;
                z += x*60+y;
            }
            a[z] = t;


        }
        map<int, int>::iterator it = a.begin();

        cout<<(*it).second<<endl;
        it++;
        cout<<(*it).second<<endl;
        it = a.end();
        it--;
        it--;
        cout<<(*it).second<<endl;
    }

    return 0;
}