#include <cstdio>
#include <cfloat>
using namespace std;

int main() {
  int n, c, m, s, b[4];
  double t, a[4];
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    a[0] = a[1] = DBL_MAX;
    a[2] = a[3] = -DBL_MAX;
    b[0] = b[1] = b[2] = b[3] = -1;
    for (int i=0; i<n; i++) {
      scanf("%d", &c);
      t = 0.;
      for (int j=0; j<4; j++) {
        scanf("%d %d", &m, &s);
        t += 60 * m + s;
      }
      if (t < a[0]) {
        a[1] = a[0];
        a[0] = t;
        b[1] = b[0];
        b[0] = c;
      } else if (t < a[1]) {
        a[1] = t;
        b[1] = c;
      }
      if (t > a[3]) {
        a[2] = a[3];
        a[3] = t;
        b[2] = b[3];
        b[3] = c;
      } else if (t > a[2]) {
        a[2] = t;
        b[2] = c;
      }
    }
    for (int i=0; i<3; i++) {
      printf("%d\n", b[i]);
    }
  }
  return 0;
}