{-
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1195&lang=jp
?????????: Encryption System
?????°:
18:50 Haskell?????????????????¨????????§Haskell????????????
19:11 ????\???¢?????±???????¨???\?????????????????????
19:24 ????\???¢?????±?????????????????????????????????????????£????????????????????§??????????????????
19:32 ?????°??£????????§?????´?????????????????????
-}
import Control.Monad
import Control.Applicative
import Data.List

main = do
 info <- getLine
 unless (info == "#") $ do
 let arr = sort $ analyze info
 print (length arr)
 mapM_ putStrLn $ if length arr <= 10 then arr else take 5 arr ++ (reverse . take 5 . reverse)arr 
 main

analyze :: String -> [String]
analyze str = return str
 >>= decipher 'z' 'y'
 >>= decipher 'y' 'x'
 >>= decipher 'x' 'w'
 >>= decipher 'w' 'v'
 >>= decipher 'v' 'u'
 >>= decipher 'u' 't'
 >>= decipher 't' 's'
 >>= decipher 's' 'r'
 >>= decipher 'r' 'q'
 >>= decipher 'q' 'p'
 >>= decipher 'p' 'o'
 >>= decipher 'o' 'n'
 >>= decipher 'n' 'm'
 >>= decipher 'm' 'l'
 >>= decipher 'l' 'k'
 >>= decipher 'k' 'j'
 >>= decipher 'j' 'i'
 >>= decipher 'i' 'h'
 >>= decipher 'h' 'g'
 >>= decipher 'g' 'f'
 >>= decipher 'f' 'e'
 >>= decipher 'e' 'd'
 >>= decipher 'd' 'c'
 >>= decipher 'c' 'b'
 >>= decipher 'b' 'a'





-- decipher 'b' 'a' "want a aeer" = ["wbnt a aeer","want b aeer","want a beer","want a aeer"]
decipher :: Char -> Char -> String -> [String]
decipher b a str
 | b `elem` str = let (front,back) = break (==b) str in map (++back) (replaceOne a b front) -- b??\???????????????????????????????????¨back?????¨??????????????£???
 | otherwise = replaceOne' a b str



-- replaceOne 'a' 'b' "an algebra" = ["bn algebra", "an blgebra", "an algebrb"]
replaceOne :: (Eq a) => a -> a -> [a] -> [[a]]
replaceOne a b = init . replaceOne' a b -- ????????????????????????

replaceOne' :: (Eq a) => a -> a -> [a] -> [[a]]
replaceOne' _ _ [] = [[]]
replaceOne' a b (c:xs)
 | a == c = (b:xs) : map (c:) (replaceOne' a b xs) -- ???????????????????????????????????¨???????????????????????¨
 | otherwise = map (c:) (replaceOne' a b xs) -- ???????????£????????????????????????????????????