T = int(input()) for _ in range(T): s = input().strip() if not s: print("impossible") continue # Check if the last character is R if s[-1] != 'R': print("impossible") continue # Check if the counts of G and R are equal count_g = s.count('G') count_r = s.count('R') if count_g != count_r: print("impossible") continue # Check that R counts never exceed G counts at any position current_g = 0 current_r = 0 possible = True for c in s: if c == 'G': current_g += 1 elif c == 'R': current_r += 1 if current_r > current_g: possible = False break if not possible: print("impossible") continue # Check that each G has at least one W before it g_positions = [i for i, char in enumerate(s) if char == 'G'] for pos in g_positions: if 'W' not in s[:pos]: possible = False break print("possible" if possible else "impossible")