#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s


int main()
{
	int n, a, b, m[8];
	vector<pair<int, int>> v;
	while (1)
	{
		v.clear();
		cin >> n; if (n == 0) return 0;
		REP(i, n)
		{
			cin >> a;
			REP(j, 8) cin >> m[j];
			b = (m[0] + m[2] + m[4] + m[6]) * 60 + (m[1] + m[3] + m[5] + m[7]);
			v.push_back(make_pair(b, a));
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl << v[1].second << endl << v[n - 2].second << endl;
	}
	return 0;
}