T = gets.to_i S = T.times.map {gets.chomp} def f(s) r = 0 g = 0 w = 0 s.reverse.each_char do |c| if c == "R" r += 1 elsif c == "G" if r == 0 return "impossible" else r -= 1 g += 1 end elsif c == "W" if g == 0 and w == 0 return "impossible" else g = [g - 1, 0].max w += 1 end end end if r == 0 and g == 0 "possible" else "impossible" end end ans = S.map {|s| f(s)} puts ans