def solve(s): numG, numR = s.count('G'), s.count('R') if numG != numR or numG == 0: return False stacks = [] for light in s: if light == 'R': stacks.append(1) elif light == 'G': for i in xrange(len(stacks)): if stacks[i] == 1: stacks[i] += 1 break else: return False else: if len(stacks) == 0 or max(stacks) == 1: return False for i in xrange(len(stacks)): if stacks[i] == 2: stacks[i] += 1 if len(stacks) == numG and min(stacks) == 3: return True break return True for t in xrange(input()): print 'possible' if solve(raw_input()[::-1]) else 'impossible'