#!/usr/bin/python # -*- coding: utf-8 -*- # よくわかんなくなった # pekempey さんのをカンニングした def check(str): W = R = 0 hasW = hasR = hasG = False for s in str: if s == 'W': W += 1 elif s == 'G': W -= 1 if W < 0: return False #前から見て白より多く緑が出たらだめ for s in str[::-1]: if s == 'W': if not hasG: return False #後ろから見て緑がないのに白があったらだめ elif s == 'G': hasG = True R -= 1 elif s == 'R': R += 1 if R < 0 : return False #後ろから見て赤より多く緑が出たらだめ return R == 0 # ? #条件それだけなのか T = input() for t in range(T): inp = raw_input() if check(inp) == True: print 'possible' else: print 'impossible'