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