T = int(input()) for _ in range(T): S = input().strip() count_g = S.count('G') count_r = S.count('R') if count_g != count_r: print("impossible") continue possible = True g_count = 0 r_count = 0 for c in S: if c == 'R': if g_count < (r_count + 1): possible = False break r_count += 1 elif c == 'G': g_count += 1 if not possible: print("impossible") continue # Check each G has at least one W before it prefix_w = [0] * (len(S) + 1) for i in range(len(S)): prefix_w[i+1] = prefix_w[i] + (1 if S[i] == 'W' else 0) for i in range(len(S)): if S[i] == 'G' and prefix_w[i] == 0: possible = False break if not possible: print("impossible") continue total_w = prefix_w[len(S)] if total_w < count_g: possible = False print("possible" if possible else "impossible")