### constant

MAX_TIME = 1 << 31 - 1

### main

while true
  n = gets.strip.to_i
  break if n == 0

  times = [MAX_TIME] * 4
  cs = [nil] * 4

  (1..4).each do
    c, m1, s1, m2, s2, m3, s3, m4, s4 = gets.strip.split(' ').map{|s| s.to_i}
    time = (m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4)

    for i in (0..3)
      if times[i] > time
        times[i + 1, 3 - i] = times[i, 3 - i]
        cs[i + 1, 3 - i] = cs[i, 3 - i]
        times[i] = time
        cs[i] = c
        break
      end
    end
  end

  (5..n).each do
    c, m1, s1, m2, s2, m3, s3, m4, s4 = gets.strip.split(' ').map{|s| s.to_i}
    time = (m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4)

    if times[0] > time
      times[1] = times[0]
      cs[1] = cs[0]
      times[0] = time
      cs[0] = c
    elsif times[1] > time
      times[1] = time
      cs[1] = c
    elsif times[3] < time
      times[2] = times[3]
      cs[2] = cs[3]
      times[3] = time
      cs[3] = c
    elsif times[2] < time
      times[2] = time
      cs[2] = c
    end
  end

  (0..2).each{|i| puts cs[i]}
end