#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<int, int> Team;

int main(void){  
  int n;
  
  while (cin >> n){
    vector<Team> v;
    if (n==0) break;
    for (int i=0; i<n; i++){
      int id, t;
      cin >> id;
      t = 0;
      for (int j=0; j<4; j++){
        int m,s;
        cin >> m >> s;
        t += m*60+s;
      }
      v.push_back(make_pair(t, id));
    }
    sort(v.begin(), v.end());
    cout << v[0].second << endl;
    cout << v[1].second << endl;
    cout << v[n-2].second << endl;
  }
  
  return 0;
}
