#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	
	while(1){
		int n;
		cin >> n;
		if(n==0)
			break;

		int c[100000];

		int m1[100000];
		int m2[100000];
		int m3[100000];
		int m4[100000];
	
		int s1[100000];
		int s2[100000];
		int s3[100000];
		int s4[100000];
		
		int ans[100000];
		int ans2[100000];
		int ans3[100000];
		for(int i=0;i<n;i++){
			cin >> c[i] >> m1[i] >> s1[i] >> m2[i] >> s2[i] >> m3[i] >> s3[i] >> m4[i] >> s4[i];
			ans[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+s1[i]+s2[i]+s3[i]+s4[i];
			ans2[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+s1[i]+s2[i]+s3[i]+s4[i];
			ans3[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+s1[i]+s2[i]+s3[i]+s4[i];
		}

		sort(ans, ans + n);
		sort(ans2, ans2 + n, greater<int>());

		for(int i=0;i<2;i++){
			for(int j=0;j<n;j++){
				if(ans[i] == ans3[j]){
					cout << c[j] << endl;
				}
			}
		}
		
		for(int i=0;i<n;i++){
			if(ans2[1] == ans3[i]){
				cout << c[i] << endl;
			}
		}

	}
		

		
	
	return 0;
}