{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE BangPatterns #-} import Control.Applicative import Control.Monad import Control.Arrow import Data.List import Data.Maybe import Data.Char import qualified Data.ByteString.Char8 as B import Text.Printf readInt = ( readLn :: IO Int ) readInts = map ( read :: String -> Int ) . words <$> getLine getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine which a b f = if f then a else b mp [ a, b ] = ( a, b ) main = getLine >> getContents >>= mapM_ putStrLn . map ( which "possible" "impossible" . f 0 0 0 . reverse ) . lines f 0 0 _ [] = True f r g w ('R':s) = f ( r + 1 ) g w s f 0 _ _ ('G':s) = False f r g w ('G':s) = f ( r - 1 ) ( g + 1 ) w s f r 0 0 ('W':s) = False f r 0 w ('W':s) = f r 0 w s f r g w ('W':s) = f r ( g - 1 ) ( w + 1 ) s f _ _ _ _ = False