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

int main(){
  int n;

  while(cin >> n){
    if(n == 0){
      break;
    }

    pair<int,int> team[n];

    for(int i = 0; i < n; i++){
      cin >> team[i].second;
      team[i].first = 0;

      for(int j = 0; j < 4; j++){
        int m, s;
        cin >> m >> s;
        team[i].first += s + m * 60;
      }
    }

    sort(team, team + n);

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