T=int(input()) for tests in range(T): S=input() W=0 G=0 R=0 flag=1 lastw=-1 lastg=-1 lastr=-1 for ind in range(len(S)): s=S[ind] if s=="G": G+=1 lastg=ind elif s=="R": R+=1 lastr=ind else: W+=1 lastw=ind if G