for i in range(int(input())): c = 0 for s in input(): if s == 'W': continue c += 1 if s == 'G' else -1 c = -float('inf') if c < 0 else c print('possible' if c == 0 else 'impossible')