def solve(S): ct = 0 for s in S: if s == 'G': ct += 1 elif s == 'R': ct -= 1 if ct < 0: return 'impossible' return 'possible' if ct == 0 else 'impossible' N = int(input()) for _ in range(N): print(solve(input()))