#include <iostream>
#include <map>
using namespace std;

int main()
{
	int n;
	while(cin >> n){
		if(!n)
			break;
		map<int,int> memo;
		int name,a,b,c,d,e,f,g,h,time=0;
		for(int i=0;i<n;i++){
			cin >> name >> a >> b >> c >> d >> e >> f >> g >> h;
			time = a*60+b+c*60+d+e*60+f+g*60+h;
			memo[time] = name;
		}
		map<int,int>::iterator it = memo.begin();
		cout << it->second << endl;
		it++;
		cout << it->second << endl;
		it = memo.end();
		it--;
		it--;
		cout << it->second << endl;
	}
	return 0;
}