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

typedef pair<int, int> P;
P sum[1000001];

int main()
{
  int n;
  while (cin >> n, n){
    for (int i = 0; i < n; i++){
      int c;
      cin >> c;
      sum[i].first = 0;
      sum[i].second = c;
      for (int j = 0; j < 4; j++){
        int m, s;
        cin >> m >> s;
        sum[i].first += m * 60 + s;
      }
    }
    sort(sum, sum + n);
    cout << sum[0].second << endl << sum[1].second << endl << sum[n - 2].second << endl;
  }
  return (0);
}