#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m, s; pair<int, int> d[1000000];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &d[i].second); d[i].first = 0;
			for (int j = 0; j < 4; j++) scanf("%d%d", &m, &s), d[i].first += m * 60 + s;
		}
		sort(d, d + n);
		printf("%d\n%d\n%d\n", d[0].second, d[1].second, d[n - 2].second);
	}
	return 0;
}