import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.Map                      as M
import           Data.List
import qualified Data.Set                      as S
import           Data.Maybe
import           Data.Ord
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n $ BS.unpack <$> BS.getLine
toPair [x, y] = (x, y)

main = do
  n <- read <$> getLine
  s <- replicateM n getLine
  mapM putStrLn $ solve s

solve :: [String] -> [String]
solve s = reverse $ g $ s' s

s' s = sortOn Data.Ord.Down $ map f $ group $ sort s

f s = (length s, head s)

g s =
  snd (head s) : map snd (takeWhile (\(l, _) -> fst (head s) == l) $ tail s)
