#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) bool check(const string &s) { int g = count(s.begin(), s.end(), 'G'); int r = count(s.begin(), s.end(), 'R'); int w = count(s.begin(), s.end(), 'W'); if (!g || !r || !w) return false; if (g != r) return false; if (w < g) return false; if (s.find_last_of("W") > s.find_last_of("G")) return false; int stk = 0; for (char c: s) { if (c == 'G') ++stk; else if (c == 'R') { if (--stk < 0) return false; } } return !stk; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { string s; cin >> s; if (check(s)) cout << "possible" << endl; else cout << "impossible" << endl; } return 0; }