N=int(input()) for i in range(N): S=input() ans=0 cnt=0 R=0 G=0 for j in range(len(S)): if S[j]=="G": ans+=1 G+=1 elif S[j]=="R": ans-=1 R+=1 if ans<0: print("impossible") R=0 j=len(S) else: cnt+=1 if len(S)==cnt+R+G: if ans==0: print("possible") else: print("impossible")