class Calc0154 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @n = args.shift.first.to_i @ss = args.map(&:first) end def calc(s) ws = s.count('W') gs = s.count('G') rs = s.count('R') !s.end_with?('W') && ws >= 1 && gs >= 1 && rs >= 1 && s.rindex('W') < s.rindex('G') && gs == rs && check_times(s) end def check_times(s) ws = gs = rs = 0 s.split(//).each do |c| ws += 1 if c == 'W' gs += 1 if c == 'G' rs += 1 if c == 'R' return false if gs > ws || rs > gs end true end def run @ss.map { |s| calc(s) }.map { |r| r ? 'possible' : 'impossible' }.join("\n") end end puts Calc0154.new(STDIN.readlines).run if __FILE__ == $0