import re T = int(input()) for i in range(T): S = input() pre_S = '' while (S != pre_S): pre_S = S S = re.sub(r'W.*G.*R', '', S) print(S) if S.count('W') == len(S): print('possible') else: print('impossible')