#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<PII> data;
    REP(i,n){
      int num,sum = 0;
      cin>>num;
      REP(j,4){
        int m,s;
        cin>>m>>s;
        sum += m*60 + s;
      }
      data.push_back(PII(sum,num));
    }
    sort(data.begin(),data.end());
    cout<<data[0].second<<endl;
    cout<<data[1].second<<endl;
    cout<<data[n-2].second<<endl;
  }
  return 0;
}