#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

P ts[10000];

int main(){
	int n;
	int c, m1, s1, m2, s2, m3, s3, m4, s4;
	while(cin >> n && n){
		rep(i, n){
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			ts[i] = P((m1+m2+m3+m4)*60+s1+s2+s3+s4, c);
		}
		sort(ts, ts + n);
		cout << ts[0].second << endl;
		cout << ts[1].second << endl;
		cout << ts[n-2].second << endl;
	}
	return 0;
}