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