for _ in range(int(input())): S = input() x = 0 y = 0 for s in reversed(S): if s == 'R': x += 1 elif s == 'G': if x: x -= 1 y += 1 else: x -= 1 break else: y -= 1 if x == 0 and y <= 0: print('possible') else: print('impossible')