#include <iostream>
using namespace std;

class Score{
public:
    int num;
    int time;
    
    Score(){
        this->num = 0;
        this->time = 0;
    }
    
    Score(int num, int time){
        this->num = num;
        this->time = time;
    }
    
};

int main(int argc, const char * argv[]) {
    
    while (true) {
        int n;
        cin >> n;
        
        if(n==0){
            break;
        }
        
        Score max,pre,biri,boobie;
        
        for(int i=0;i<n;i++){
            int c1;
            cin >> c1;
            int sum = 0;
            for(int i=0;i<4;i++){
                int m, s;
                cin >> m >> s;
                sum+= 60*m + s;
            }
            
            if(max.time == 0 || max.time > sum){
                pre = max;
                max = Score(c1,sum);
            }
            else if(pre.time == 0 || pre.time > sum){
                if(biri.time == 0){
                    biri = pre;
                }
                else if(boobie.time == 0){
                    boobie = pre;
                }
                pre = Score(c1,sum);
            }
            else if(biri.time < sum){
                boobie = biri;
                biri = Score(c1,sum);
            }
            else if(boobie.time < sum){
                boobie = Score(c1,sum);
            }
            
        }
        
        cout << max.num << endl;
        cout << pre.num << endl;
        cout << boobie.num << endl;
        
    }
    
    return 0;
}