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