#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
template <class X> void print(X Target){ cout << Target << '\n'; }

struct PRO{
  int num;
  int t;
};

bool comp(PRO lhs, PRO rhs)
{
  return (lhs.t < rhs.t);
}

signed main()
{
  ios::sync_with_stdio(false);
  int n;

  while (cin >> n, n){
    vector<PRO> rank;
    REP(i, n){
      int c, m1, s1, m2, s2, m3, s3, m4, s4;
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      rank.pb((PRO){c, (m1 + m2 + m3 + m4) * 60 + s1 + s2 + s3 + s4});
    }
    sort(rank.begin(), rank.end(), comp);
    print(rank[0].num);
    print(rank[1].num);
    print(rank[rank.size() - 2].num);
  }

  return (0);
}