#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a, b, n;
pair<int, int>x[8000000];
int main() {
	while (true){
		memset(x, 0, sizeof(x));
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++){
			cin >> x[i].second;
			for (int i = 0; i < 4; i++) {
				cin >> a >> b;
				x[i].first += a * 60 + b;
			}
		}
		sort(x, x + n);
		cout << x[0].first << endl << x[1].first << endl << x[n - 2].first << endl;
	}
}