import Control.Applicative import Control.Monad import Data.List import Debug.Trace check :: String -> String check str = trace str $ if check_sub 0 0 str then "possible" else "impossible" where check_sub r g (x:xs) | null xs = r == 0 && g <= 1 && x == 'W' | x == 'R' = check_sub (r+1) g xs | x == 'G' = if r > 0 then check_sub (r-1) (g+1) xs else False | x == 'W' = if g > 0 then check_sub r (g-1) xs else check_sub r 0 xs main = do mapM_ putStrLn =<< map (check.reverse) <$> drop 1 <$> lines <$> getContents