#include<bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);

int main()
{
  int n;
  while( cin >> n, n ) {
    int max1 = 0, max2 = 0, min1 = INF, min2 = INF;
    int max1_n, max2_n, min1_n, min2_n;

    for(int i=0; i<n; i++) {
      int c1, m1, s1, m2, s2, m3, s3, m4, s4;
      int sum = 0;
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      sum += m1*60 +  s1 + m2*60 +  s2 + m3*60 +  s3 + m4*60 + s4;
      if( sum > max1 ) {
	max2 = max1; 
	max2_n = max1_n;
	max1 = sum;
	max1_n = c1;
      } 
      else if( sum > max2 ) {
	max2 = sum;
	max2_n = c1;
      }
      if( sum < min1 ) {
	min2 = min1; 
	min2_n = min1_n;
	min1 = sum;
	min1_n = c1;
      }
      else if( sum < min2 ) {
	min2 = sum;
	min2_n = c1;
      }
    }

    cout << min1_n << endl << min2_n << endl << max2_n << endl;
  }

}