gets.to_i.times{ s = gets.chomp g = s.count('G') r = s.count('R') w = s.count('W') if g != r || w < g puts "impossible" else s.reverse =~ /R(.*?)G/ if s[-1] != 'R' || s[0] != 'W' || $1.include?('W') puts "impossible" else g.times{ s.gsub!(/WG(.*?)R/){$1} } if s.include?('R') puts "impossible" else puts "possible" end end end }