#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int id[100010], t[100010] = {}, ord[100010];
    iota(ord, ord + n, 0);
    for (int i = 0; i < n; i++) {
      cin >> id[i];
      for (int j = 0; j < 4; j++) {
        int m, s;
        cin >> m >> s;
        t[i] += m * 60 + s;
      }
    }
    sort(ord, ord + n, [&](int a, int b) {
      return t[a] < t[b];
    });
    cout << id[ord[0]] << endl;
    cout << id[ord[1]] << endl;
    cout << id[ord[n - 2]] << endl;
  }

  return 0;
}
