import Data.List

take' :: [Int] -> [String] -> [String]
take' [] xs = xs
take' (n:ns) xs = take' ns (take n xs ++ tail (xs!!n):[] ++ drop (n+1) xs)

solve :: [String] -> String
solve xs
  | elemIndex [] xs /= Nothing = []
  | 1 == (length . f) xs = f xs ++ solve (map tail xs)
  | otherwise = solve (take' (elemIndices (head $ sort $ map head xs) $ map head xs) xs)
    where f = nub . map head

main = getContents >>= putStrLn . solve . map sort . tail . lines