#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;

int main(){
        
    int n;
    vector<pair<int,int> > score;
    
    
    while(cin >> n, n!=0 ){
        
        score.clear();
        
        for(int i=0; i<n; i++){
            int id,m,s,sum=0;
            cin >> id;
            for(int j=0; j<4; j++){
                cin >> m >> s;
                sum += m*60 + s;
            }
            score.push_back(make_pair(sum,id));
        }
        
        sort(score.begin(),score.end());
        
        cout << score[0].second << endl;
        cout << score[1].second << endl;
        cout << score[score.size()-2].second << endl;
    }
    return 0;
}
