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

int main(int argc, const char * argv[])
{
    while (1) {
        int n; cin >> n;
        if (n == 0) break;
        int result[2][n];
        for (int i = 0; i < n; i++) {
            int m1, s1, m2, s2, m3, s3, m4, s4;
            cin >> result[0][i] >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            result[1][i] = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < n-1; j++) {
                if (result[1][j] > result[1][j+1]) {
                    int tmp[2];
                    tmp[0] = result[0][j];
                    tmp[1] = result[1][j];
                    result[0][j] = result[0][j+1];
                    result[1][j] = result[1][j+1];
                    result[0][j+1] = tmp[0];
                    result[1][j+1] = tmp[1];
                }
            }
        }
        cout << result[0][0] << endl << result[0][1] << endl << result[0][n-2] << endl;
    }
    return 0;
}