T = int(input()) for _ in range(T): S = input().strip() g_count = 0 r_count = 0 possible = True # Check if the number of G and R are equal g_total = S.count('G') r_total = S.count('R') if g_total != r_total: print("impossible") continue # Check each G has at least one W before it has_w = False for c in S: if c == 'W': has_w = True elif c == 'G': if not has_w: possible = False break if not possible: print("impossible") continue # Check R's and G's order using a stack-like approach current_g = 0 for c in S: if c == 'G': current_g += 1 elif c == 'R': if current_g <= 0: possible = False break current_g -= 1 if possible and current_g == 0: print("possible") else: print("impossible")