#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#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 INF 1<<30
typedef pair<int,int> pii;
int main() {
  int n;
  while(cin>>n,n) {
    vector<pii> v;
    while(n--) {
      int c;
      cin >> c;
      int time = 0;
      REP(i,4) {
        int m,s;
        cin >> m >> s;
        time += m*60+s;
      }
      v.push_back(pii(time,c));
    }
    sort(ALL(v));
    cout << v[0].second << endl;
    cout << v[1].second << endl;
    cout << v[v.size()-2].second << endl;
  }
}