#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		vector<pair<int,int> > ts;
		for(int i = 0; i < n; i++){
			int team;
			int m[4];
			int s[4];
			cin>>team>>m[0]>>s[0]>>m[1]>>s[1]>>m[2]>>s[2]>>m[3]>>s[3];
			int time=0;
			for(int i = 0; i < 4; i++){
				time+=m[i]*60;
				time+=s[i];
			}
			ts.push_back(make_pair(time,team));
		}
		sort(ts.begin(),ts.end());
		cout<<ts[0].second<<endl;
		cout<<ts[1].second<<endl;
		cout<<ts[ts.size()-2].second<<endl;

	}

	return 0;
}