while (num = gets.to_i) != 0
  result = []
  num.times do
    tmp_ary = gets.split.map(&:to_i)
    result << tmp_ary.slice!(0)
    minutes = 0
    seconds = 0
    tmp_ary.each_with_index do |value, index|
        minutes += value if index.even?
        seconds += value if index.odd?
    end
    result << minutes * 60 + seconds
  end
  team_hash = Hash[Hash[*result].sort_by {|k, v| v}]
  team_ary = team_hash.keys
  puts team_ary[0], team_ary[1], team_ary[team_ary.size - 2]
end