import Data.List      -- sortBy
import Data.Ord       -- comparing
import Control.Monad  -- replicateM

totalTime (c:ts) = (c, totalTime' ts)
totalTime' [] = 0
totalTime' (m:s:ts) = m * 60 + s + totalTime' ts

main = do
  n <- readLn
  if n == 0
    then return ()
    else do main' n
            main

main' n = do
  ls <- replicateM n getLine
  let ts     = map (totalTime . map read . words) $ ls
      sorted = map fst . sortBy (comparing snd) $ ts
  print (sorted !! 0)
  print (sorted !! 1)
  print (sorted !! (length sorted - 2))