for _ in range(int(input())): s=list(input()) s.reverse() a,b,c=0,0,0;d=1;t=0 for i in s: if i=="R": a+=1 elif i=="G": b+=1;t+=1 if a