#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main() {
	int n;
	while(cin >> n, n) {
		vector<pair<int,int> > v;
		for(int i = 0; i < n; i++) {
			int c;
			cin >> c;
			int pts = 0;
			for(int i = 0; i < 4; i++) {
				int m, s;
				cin >> m >> s;
				pts += m * 60 + s;
			}
			v.push_back(pair<int,int>(pts, c));
		}
		sort(v.begin(), v.end());

		cout << v[0].second << endl;
		cout << v[1].second << endl;
		cout << v[v.size() - 2].second << endl;
	}
}