import Control.Monad (liftM, forM_) import Text.Printf msg = "welcome to code jam" count' :: String -> [Integer] count' [] = replicate (length msg) 0 count' (c:cs) = zipWith (+) xs [if c==c' then n else 0 | (c',n) <- zip msg (tail xs ++ [1])] where xs = count' cs count :: String -> Integer count = head . count' main :: IO () main = do n <- liftM read getLine forM_ [(1::Int)..n] $ \x -> do s <- getLine printf "Case #%d: %04d\n" x (count s `mod` 10000)