#include <iostream>
using namespace std;

int main(){
  int n;

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

    int c[n];
    int score[n];

    for(int i = 0; i < n; i++){
      cin >> c[i];
      score[i] = 0;

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

    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        if(score[i] > score[j]){
          swap(c[i], c[j]);
          swap(score[i], score[j]);
        }
      }
    }

    cout << c[0] << endl;
    cout << c[1] << endl;
    cout << c[n - 2] << endl;
  }
}