#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

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