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