#include<iostream>
#include<vector>

using namespace std;


int main(){
	int temp, i, j, teams, total,number;
	vector<int> name;
	vector<int> time;
	time.insert(time.begin(), 99999);
	

	while (1){
		cin >> teams;
		
		if (teams == 0){
			break;
		}
		
		for (i = 0; i < teams; i++){
			cin >> number;
			total = 0;
			for (j = 0; j < 4; j++){
				cin >> temp;
				total += temp * 60;
				cin >> temp;
				total += temp;
			}

			for (j = 0; j <= i; j++){
				if (total < time[j]){
					name.insert(name.begin()+j, number);
					time.insert(time.begin()+j, total);
					break;
				}
				
			}

		}
		
		cout << name[0] << endl << name[1] << endl << name[i-2] << endl;


		//for (j = 0; j < i; j++){
		//	cout << name[j] << endl;
		//}


		name.clear();
		time.clear();
		time.insert(time.begin(),99999);
	}
}