#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
using namespace std;

pair<int, int> team[1000000];
//team[i].firstはかかった時間[s]
//team[i].secondはチーム番号

int main()
{
	int n;
	int m, s;
	while (cin >> n)
	{
		for (int i = 0; i < n; i++)
		{
			team[i].first = 0;
			cin >> team[i].second;
			for (int j = 0; j < 4; j++)
			{
				cin >> m >> s;
				team[i].first += m * 60 + s;
			}
		}

		int first = 0, worst = 0;
		int second = 0, booby = 0;

		for (int i = 0; i < n; i++)
		{
			if (team[first].first > team[i].first)
			{
				second = first;
				first = i;
			}
			else if (team[second].first > team[i].first)
			{
				second = i;
			}

			if (team[worst].first < team[i].first)
			{
				booby = worst;
				worst = i;
			}
			else if (team[booby].first < team[i].first)
			{
				booby = i;
			}

			if (i == 1)
			{
				second = worst;
				booby = first;
			}
		}
		cout << team[first].second << endl;
		cout << team[second].second << endl;
		cout << team[booby].second << endl;
	}
	
	return 0;
}