graph1 = zip s f
  where
    s = " ',-.?" ++ ['A'..'Z']
    f = ["101","000000","000011","10010001","010001","000001","100101","10011010",
         "0101","0001","110","01001","10011011","010000","0111","10011000",
         "0110","00100","10011001","10011110","00101","111","10011111","1000",
         "00110","00111","10011100","10011101","000010","10010010","10010011","10010000"]
graph2 = zip f2 s2
  where
    f2 = ["00000","00001","00010","00011","00100","00101","00110","00111",
          "01000","01001","01010","01011","01100","01101","01110","01111",
          "10000","10001","10010","10011","10100","10101","10110","10111",
          "11000","11001","11010","11011","11100","11101","11110","11111"]
    s2 = ['A'..'Z'] ++ " .,-'?"

change1 :: String -> String
change1 [] = []
change1 (x:xs) = (getG1 x graph1) ++ (change1 xs)
  where
    getG1 :: Char -> [(Char,String)] -> String
    getG1 x [] = []
    getG1 x ((k,v):r)
      | x == k = v
      | otherwise = getG1 x r

change2 :: String -> String
change2 [] = []
change2 (x1:x2:x3:x4:x5:r) = (getG2 [x1,x2,x3,x4,x5] graph2) : (change2 r)
change2 xs = [getG2 (xs ++ (replicate (5 - length xs) '0')) graph2]

getG2 :: String -> [(String,Char)] -> Char
getG2 s ((k,v):r)
  | s == k = v
  | otherwise = getG2 s r

main :: IO ()
main = do
  ls <- getContents
  let ls' = lines ls
      ansL = map (change2 . change1) ls'
  mapM_ putStrLn ansL