import Data.List
import Data.Ord

main = interact $ unlines . map (show' . winner) . read' . lines
 where
  read' ("0":_) =[]
  read' (n:cs:xs) = (read n, words cs) : read' xs
  show' = maybe "TIE" (\(c,d) -> [c] ++ " " ++ show d)

winner (n,cs) = winner' [] cs
 where
  winner' vs [] = Nothing
  winner' vs (c:cs)
   | projected (c++vs) = Just (elected (c++vs), n - length cs)
   | otherwise = winner' (c++vs) cs
  projected vs = case reverse $ sortBy (comparing length) $ group $ sort vs of
   [_]     -> length vs > div n 2 
   (f:s:_) -> length f - length s > n - length vs
  elected = head . last . sortBy (comparing length) . group . sort