gets.to_i.times{ s = gets.chomp tmp = s.count('G') if tmp != s.count('R') || s.count('W') == 0 puts "impossible" else s.reverse =~ /R(.*?)G/ if s.rindex('R') != s.length - 1 || $1.include?('W') puts "impossible" else tmp.times{ s.sub!(/G(.*?)R/){$1} } if s.include?('R') puts "impossible" else puts "possible" end end end }