from collections import Counter def solve(s: str) -> bool: t = Counter() used_g = False for c in reversed(s): match c: case 'W': if not used_g: return False if t['G'] > 0: t['G'] -= 1 case 'G': if t['R'] == 0: return False used_g = True t['R'] -= 1 t['G'] += 1 case 'R': t['R'] += 1 if t['R'] or t['G']: return False return True T = int(input()) for _ in range(T): S = input() if solve(S): print('possible') else: print('impossible')