t = int(input()) ans = [] for i in range(t): s = list(input()) ss = list(s) f = 0 count_w = 0 count_g = 0 count_r = 0 while(ss): wgr = ss.pop(-1) if wgr == 'W': count_w += 1 if count_w > count_g: f = 1 break elif wgr == 'G': count_g += 1 elif wgr == 'R': count_r += 1 if count_g > 0 and count_r > 0: break count = 0 count_w = 0 count_g = 0 count_r = 0 while(s): wgr = s.pop(0) if wgr == 'W': count_w += 1 continue elif wgr == 'G': count += 1 count_g += 1 elif wgr == 'R': count -= 1 count_r += 1 if count < 0: f = 1 if f == 0 and count == 0 and count_w >= count_g: ans.append('possible') else: ans.append('impossible') for j in ans: print(j)