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

int main(void){
  int n;
  while(cin >> n && n != 0){
    int c, m1, s1, m2, s2, m3, s3, m4, s4;
    vector<pair<int, int> > team;
    for(int i = 0; i < n; i++){
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      int time = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
      team.push_back(pair<int, int>(time, c));
    }
    sort(team.begin(), team.end());
    cout << team[0].second << endl;
    cout << team[1].second << endl;
    cout << team[team.size() - 2].second << endl;
  }
  return 0;
}