import Control.Applicative
import Control.Monad
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M

main :: IO ()
main = do
  n <- readLn
  solve <$> replicateM n B.getLine >>= mapM_ B.putStrLn

solve :: [ByteString] -> [ByteString]
solve ss = let imp = M.empty :: Map ByteString Int
               mp = foldl' (\m s -> M.insertWith (+) s 1 m) imp ss
           in sort $
              snd $
              M.foldlWithKey' (\(ct, ls) k v ->
                                             if ct < v then (v, [k])
                                             else if ct == v then (ct, k:ls)
                                                  else (ct, ls)) (0, []) mp
