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