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