for _ in[0]*input(): s=list(raw_input()) while 1: w=g=r=-1 for i in xrange(len(s)): if s[i]=="W" and w==-1: w=i elif s[i]=="G" and g==-1: g=i elif s[i]=="R" and r==-1: r=i if w>=0 and g>=0 and r>=0: break if w>=0 and g>=0 and r>=0 and w