#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
int main(){
  int n;
  while(cin >> n, n){
    vector<pair<int,string>> V;
    for(int i = 0; i < n; ++i){
      string id;
      cin >> id;
      int t = 0;
      for(int i = 0; i < 4; ++i){
        int m, s;
        cin >> m >> s;
        t += m*60 + s;
      }
      V.emplace_back(t,id);
    }
    sort(V.begin(),V.end());
    cout << V[0].second << endl;
    cout << V[1].second << endl;
    cout << V[n-2].second << endl;
  }
}

