#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Team{
public:
	Team(int x,int y){n=x;t=y;}
	int n;
	int t;
	bool operator<(const Team arg)const{
		if(t < arg.t){
			return true;
		}else{
			return false;
		}
	}
};
int main(void){
	int n,m,s,t,no;
	while(cin >> n && n){
		vector<Team> v;
		for(int i=0;i<n;i++){
			cin >> no;
			t=0;
			for(int j=0;j<4;j++){
				cin >> m >> s;
				t += m*60+s;
			}
			v.push_back(Team(no,t));
		}
		sort(v.begin(), v.end());
		cout << v[0].n << endl;
		cout << v[1].n << endl;
		cout << v[v.size()-2].n << endl;
	}
}