#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-4;
bool eq(double a, double b)
{
	return abs(a - b) < Eps;
}

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		pair<int, int> best[4];
		pair<int, int> worst[3];
		for (int i = 0; i < 4; ++i)
			best[i] = make_pair(10000000, 0);
		for (int i = 0; i < 3; ++i)
			worst[i] = make_pair(0, 0);
		while (n--)
		{
			int id;
			scanf("%d", &id);
			int total = 0;
			for (int i = 0; i < 4; ++i)
			{
				int m, s;
				scanf("%d %d", &m, &s);
				total += m*60 + s;
			}
			best[3] = worst[0] = make_pair(total, id);
			sort(best, best+4);
			sort(worst, worst+3);
		}
		printf("%d\n%d\n%d\n", best[0].second, best[1].second, worst[1].second);
	}

	return 0;
}