import Data.List(sort, inits, tails)
import Control.Arrow

main :: IO ()
main = do
    _ <- getLine
    putStr . unlines . map unwords . tail . uncurry (zipWith (++)) . (map sort . inits &&& tails) . words =<< getLine