def isinvalid (str) bus = 0 until str =~ /^W*$/ isvalid = str =~ /^(W*?)WG([WG]*?)R(.*)$/ return true unless isvalid str = "#{$1}#{$2}#{$3}" end false end def main () flandre = gets.chomp.to_i(10) for i in 0...flandre do str = gets.chomp x = "" x << "im" if isinvalid(str) puts x << "possible" end end main()