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