while 1:

  n = eval(input())

  if n==0: break

  d = [0]*n

  for i in range(n):

    x = list(map(int, input().split()))

    d[i]=[sum(x[1::2])*60+sum(x[2::2]),x[0]]

  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 = [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 = [0] * n
    for i in range(n):
        x = list(map(int, input().split()))
        d[i] = [sum(x[1::2]) * 60 + sum(x[2::2]), x[0]]
    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 = [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])

-    d = [0] * n -    for i in range(n): -        x = list(map(int, input().split())) -        d[i] = [sum(x[1::2]) * 60 + sum(x[2::2]), x[0]] -    d = sorted(d) -    print(d[0][1]) -    print(d[1][1]) -    print(d[-2][1]) +    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])