#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		int first = 100000;
		int second = 100000;
		int boobee = -1;
		int last = -1;
		
		string fir = "";
		string sec = "";
		string boo = "";
		string las = "";
		
		for(int loop = 0; loop < n; loop++){
			string str;
			int a, b;
			cin >> str;
			int sum = 0;
			for(int i = 0; i < 4; i++){
				cin >> a >> b;
				sum += a * 60 + b;
			}
			if(sum < first){
				second = first;
				first = sum;
				sec = fir;
				fir = str;
			}else if(sum < second){
				second = sum;
				sec = str;
			}
			if(sum > last){
				boobee = last;
				last = sum;
				boo = las;
				las = str;
			}else if(sum > boobee){
				boobee = sum;
				boo = str;
			}
		}
		
		cout << fir << endl << sec << endl << boo << endl;
		
	}
	return 0;
}