def check(S): depth = 0 for c in S: if c == 'G': depth += 1 elif c == 'R': depth -= 1 if depth < 0: return False return depth == 0 T = input() for i in xrange(T): S = raw_input() if check(S): print 'possible' else: print 'impossible'