def is_possible(s): g_count = s.count('G') r_count = s.count('R') if g_count != r_count: return False w_count = s.count('W') if w_count < g_count: return False # Check each G has at least one W before it n = len(s) prefix_w = [0] * (n + 1) for i in range(n): prefix_w[i+1] = prefix_w[i] + (1 if s[i] == 'W' else 0) for i in range(n): if s[i] == 'G' and prefix_w[i] == 0: return False # Check R count never exceeds G count during processing current_g = 0 current_r = 0 for c in s: if c == 'G': current_g += 1 elif c == 'R': current_r += 1 if current_r > current_g: return False return True T = int(input()) for _ in range(T): S = input().strip() if is_possible(S): print("possible") else: print("impossible")