#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,N) for(long long int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

ll n, a, c[1000010][5],no[10];
vector<ll> vl;

int main(){
	while (cin >> n){
		if (!n)break;
		REP(i, n){
			c[i][1] = 0;
			REP(j, 9){
				if (j == 0){
					cin >> c[i][j];
					continue;
				}
				cin >> a;
				if (j % 2 != 0){
					a *= 60;
				}
				c[i][1] += a;
			}
			vl.push_back(c[i][1]);
		}
		sort(ALL(vl));
		REP(i, n){
			if (c[i][1] == vl[0]){
				no[0] = c[i][0];
			}
			else if (c[i][1] == vl[1]){
				no[1] = c[i][0];
			}
			if (c[i][1] == vl[n - 2]){
				no[2] = c[i][0];
			}
		}
		REP(i, 3){
			cout << no[i] << endl;
		}
		vl.clear();
	}
}