def solve(): import sys input = sys.stdin.read().split() T = int(input[0]) cases = input[1:T+1] for S in cases: # Check counts of R and G count_R = S.count('R') count_G = S.count('G') if count_R != count_G: print("impossible") continue # Precompute prefix sum of W's n = len(S) prefix = [0] * n current = 0 for i in range(n): if S[i] == 'W': current += 1 prefix[i] = current stack = [] possible = True # Iterate from the end to the start for i in reversed(range(n)): c = S[i] if c == 'R': stack.append(i) elif c == 'G': if not stack: possible = False break # Pop the R r_pos = stack.pop() # Check if there's at least one W before this G if i == 0: possible = False break if prefix[i-1] < 1: possible = False break # After processing all characters, stack should be empty if stack: possible = False print("possible" if possible else "impossible") solve()