import Control.Applicative ((<$>)) import Control.Monad (replicateM) import Data.Vector.Unboxed (Vector, (!)) import qualified Data.Vector.Unboxed as V main :: IO () main = do n <- readLn solve <$> replicateM n getLine >>= mapM_ print solve :: [String] -> [Int] solve = map goodproblem goodproblem :: String -> Int goodproblem s = minimum [(vg ! i) + (vp ! j)| i <- [0 .. (ln - 11)], j <- [(i+4) .. (ln - 7)]] where ln = length s vg = mkv s "good" (ln - 10) vp = mkv s "problem" (ln - 6) mkv :: String -> String -> Int -> Vector Int mkv s1 s2 n = V.unfoldr f (0, s1) where f (i, _) | i == n = Nothing f (i, s) = Just (sum (zipWith (\c1 c2 -> if c1 == c2 then 0 else 1) s2 s) , (i+1, tail s))