#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > time(n);
        for(int i=0; i<n; ++i){
            cin >> time[i].second;
            time[i].first = 0;
            for(int j=0; j<4; ++j){
                int m, s;
                cin >> m >> s;
                time[i].first += m * 60 + s;
            }
        }
        sort(time.begin(), time.end());

        cout << time[0].second << endl;
        cout << time[1].second << endl;
        cout << time[n-2].second << endl;
    }
}