#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)

int main(){
    int n;
	while(cin >> n, n) {
		vector<pair<int, int> > v;
		rep(i,n) {
			pair<int, int> p;
			int s=0, m;
			cin >> p.second;
			rep(j,4) {
				cin >> m;
				s += m * 60;
				cin >> m;
				s += m;
			}
			p.first = s;
			v.push_back(p);
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl << v[1].second << endl << v[v.size()-2].second << endl;
	}
    return 0;
}