#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> P;

int main(void) {
  int n;
  while (cin >> n, n) {
    vector<P> v(n, P(0, 0));
    int id, m, s;    
    for (int i = 0; i < n; i++) {
      cin >> id;
      v[i].second = id;
      for (int j = 0; j < 4; j++) {
        cin >> m >> s;
        v[i].first += m * 60 + s;
      }
    }
    
    sort(v.begin(), v.end());

    cout << v[0].second << endl;
    cout << v[1].second << endl;
    cout << v[n - 2].second << endl;
  }

  return 0;
}
