module Main where main :: IO () main = do i <- readLn s <- getContents mapM_ (putStrLn . isPossible) . take i . lines $ s isPossible :: String -> String isPossible s = if take1RGW s then "possible" else "impossible" where take1RGW = takeR . reverse takeR (x:xs) = if x == 'R' then takeG xs else False takeG xs = case break (=='G') xs of (_, "") -> False (ys, (_:zs)) -> takeRGW (ys ++ zs) takeRGW xs | all (=='W') xs = True | otherwise = takeR (dropWhile (=='W') xs)