n_t=gets.to_i n_t.times{ str=gets.chomp.reverse r=0 g=0 f=nil s=nil str.chars{|c| if c == 'R' r+=1 elsif c == 'G' f=true if r<=0 r-=1 g+=1 elsif c =='W' f=true if g<=0 && !s g-=1 if g>0 s=true end } f |= 0