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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(cin>>n,n){
    vector<pair<int,int> > top(2,mp(0,0)), worst(2,mp(INT_MAX,0));

    REP(i,n){
      int num; cin>>num;
      int total = 0;
      REP(j,4){
	int m, s; cin>>m>>s;
	s += 60 * m;
	total += s;
      }
      pair<int,int> tmp = mp(total,num);

      if(top[1].f < tmp.f){
	top[1] = tmp;
	if(top[1].f > top[0].f)
	  swap(top[1],top[0]);
      }

      if(worst[1].f > tmp.f){
	worst[1] = tmp;
	if(worst[1].f < worst[0].f)
	  swap(worst[1], worst[0]);
      }

    }
    cout << worst[0].s << endl;
    cout << worst[1].s << endl;
    cout << top[1].s << endl;
  }
  return 0;
}