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