#include <bits/stdc++.h>

using namespace std;

int main(){
	int N;
	while(true){
		cin >> N;
		if(N == 0)break;
		int DATA[N+1][2];
		int score = 0,n1,n2;
		for(int i = 0;i < N;i++){
			cin >> DATA[i][0];
			for(int j = 0;j < 8 / 2;j++){
				cin >> n1 >> n2;
				score += (n1 * 60) + n2; 
			}
			DATA[i][1] = score;
			score = 0;
		}
		int max = -1;
		int z = 0,c = 0;
		for(int i = 0;i < N;i++){
			for(int j = 0;j < N;j++){
				if(max < 0){
					max = DATA[j][1];
					c = j;
				}else if(max > DATA[j][1] and DATA[j][1] >= 0){
					max = DATA[j][1];
					c = j;
				}
			}
			if(i <= 1 or i == N-2){
			cout << DATA[c][0] << endl;
			}
			DATA[c][1] = -1;
			c=0;
			max = -1;
		}
	}
}