for _ in range(int(input())): w = g = 0 b = False for c in input(): if c == 'W': w += 1 b = False elif c == 'G': if w == 0: b = False break w -= 1 g += 1 b = True elif g != 0: g -= 1 if g==0 and b: print('possible') else: print('impossible')