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[-1] != 'R' || $1.include?('W') puts "impossible" else s.delete!('W') loop{ s.gsub!(/G(.*)R/){$1} if $&.nil? break end } if s.include?('R') puts "impossible" else puts "possible" end end end }