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