import Control.Applicative import Control.Monad import Data.Bool (bool) main :: IO () main = do n <- readLn map solve <$> replicateM n getLine >>= mapM_ putStrLn solve :: String -> String solve bs = bool "impossible" "possible" $ last bs == 'R' && f 0 bs where f g [] = g == 0 f g (b:bs) | b == 'R' = if g > 0 then f (g - 1) bs else False | b == 'G' = f (g + 1) bs | otherwise = f g bs