import Control.Monad

main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n getLine
      let ls' = map (map (read :: String -> Int)) (map words ls)
          ts = map makeTuple ls'
          top = takeTop ts
          sec = takeTop (filter (/= top) ts)
          wor = takeWorst ts
          buu = takeWorst (filter (/= wor) ts)
      putStrLn $ show (fst top)
      putStrLn $ show (fst sec)
      putStrLn $ show (fst buu)
      main

makeTuple :: [Int] -> (Int,Int)
makeTuple [id,m1,s1,m2,s2,m3,s3,m4,s4] = (id,m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4)

takeTop :: [(Int,Int)] -> (Int,Int)
takeTop ts = foldl1 f ts
  where f (i1,t1) (i2,t2)
          |t1 > t2 = (i2,t2)
          |otherwise = (i1,t1)

takeWorst :: [(Int,Int)] -> (Int,Int)
takeWorst ts = foldl1 f ts
  where f (i1,t1) (i2,t2)
          |t1 < t2 = (i2,t2)
          |otherwise = (i1,t1)