for _ in range(int(input())): S = input() a = 0 f = True for s in S: if s == "G": a += 1 if s == "R": a -= 1 if a < 0: f = False if not f or a != 0: print("impossible") else: print("possible")