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