#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

int main() {
	while (1) {
		map<int, int>s;
		int a;
		cin >> a;
		if (a == 0)break;
		for (int b = 0; b < a; b++) {
			int c, d, e, f, g, h, i, j, k;
			cin >> c >> d >> e >> f >> g >> h >> i >> j >> k;
			s.insert(pair<int, int>((d + f + h + j) * 60 + e + g + i + k, c));
		}
		auto u = s.begin();
		cout << u->second << endl;
		u++;
		cout << u->second << endl;
		u = s.end();
		u--;
		u--;
		cout << u->second << endl;
	}
}