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') p s tmp.times{ s.gsub!(/G(.*)R/){$1} } if s.include?('R') puts "impossible" else puts "possible" end end end }