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

struct hoge{
	int num, timem, times;
};

int main(){
	int n, c, m1, s1, m2, s2, m3, s3, m4, s4;
	hoge set[100];
	while(1){
		cin >>n;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >>c >>m1 >>s1 >>m2 >>s2 >>m3 >>s3 >>m4 >>s4;
			set[i].num = c;
			set[i].timem = m1 + m2 + m3 + m4;
			set[i].times = s1 + s2 + s3 + s4;
			if(set[i].times >= 60){
				set[i].timem += set[i].times / 60;
				set[i].times %= 60;
			}
		}
		
		for(int i = 0; i < (n - 1); i++){
			for(int j = (i + 1); j < n; j++){
				if(set[j].timem < set[i].timem){
					swap(set[i].num, set[j].num);
					swap(set[i].timem, set[j].timem);
					swap(set[i].times, set[j].times);
				} else if(set[j].timem == set[i].timem){
					if(set[j].times < set[i].times){
						swap(set[i].num, set[j].num);
						swap(set[i].timem, set[j].timem);
						swap(set[i].times, set[j].times);
					}
				}
			}
		}
		
		cout <<set[0].num <<endl <<set[1].num <<endl <<set[n - 2].num <<endl;
	}
	return 0;
}