while 1:

  n = eval(input())

  if n==0: break

  D = [0]*n

  for j in range(n):

    a,b,c,d,e,f,g,h,i = list(map(int, input().split()))

    D[j] = [(b+d+f+h)*60 + c+e+g+i, a]

  D = sorted(D)

  print(D[0][1])

  print(D[1][1])

  print(D[-2][1])
while 1:

  n = eval(input())

  if n==0: break

  D = {}

  for j in range(n):

    a,b,c,d,e,f,g,h,i = list(map(int, input().split()))

    D[(b+d+f+h)*60 + c+e+g+i] = a

  A = sorted(D)

  for i in [0,1,-2]: print(D[A[i]])
while 1:
    n = eval(input())
    if n == 0:
        break
    D = [0] * n
    for j in range(n):
        a, b, c, d, e, f, g, h, i = list(map(int, input().split()))
        D[j] = [(b + d + f + h) * 60 + c + e + g + i, a]
    D = sorted(D)
    print(D[0][1])
    print(D[1][1])
    print(D[-2][1])

while 1:
    n = eval(input())
    if n == 0:
        break
    D = {}
    for j in range(n):
        a, b, c, d, e, f, g, h, i = list(map(int, input().split()))
        D[(b + d + f + h) * 60 + c + e + g + i] = a
    A = sorted(D)
    for i in [0, 1, -2]:
        print(D[A[i]])

-    D = [0] * n +    D = {} -        D[j] = [(b + d + f + h) * 60 + c + e + g + i, a] -    D = sorted(D) -    print(D[0][1]) -    print(D[1][1]) -    print(D[-2][1]) +        D[(b + d + f + h) * 60 + c + e + g + i] = a +    A = sorted(D) +    for i in [0, 1, -2]: +        print(D[A[i]])