#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

struct Team {
  int id, time;
  bool operator < (const Team& a) const { return time < a.time; }
};

int n;
Team teams[1000002];

void solve() {
  rep (i,n) {
    cin >> teams[i].id;
    teams[i].time = 0;
    int m, s;
    rep (j,4) {
      cin >> m >> s;
      teams[i].time += m * 60 + s;
    }
  }
  sort(teams, teams + n);
  const int ar[3] = { 0, 1, n-2 };
  rep (i,3) cout << teams[ ar[i] ].id << endl;
}

int main() {
  while (cin >> n, n) { 
    solve();
  }
  return 0;
}