{-
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 ?????°??£????????§?????´?????????????????????
19:33 AC???????????§?????¬??????????????´???
-}
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 = fold arr str
 where arr = map (uncurry decipher) $ zip ['b' ..'z'] ['a' .. 'y']

fold :: (Monad m) => [a -> m a] -> a -> m a
fold [] a = return a
fold (g:fs) a = fold fs a >>= g




-- 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) -- ???????????£????????????????????????????????????