#include #include #include using namespace std; int main() { int T; cin >> T; for(int t = 0; t < T; t++) { string s; const string ok = "possible", ng = "impossible"; cin >> s; reverse(s.begin(), s.end()); int G, R, W; bool flg = true; bool fr = false, fg = false; R = G = W = 0; for(int i = 0; i < s.size(); i++) { if(s[i] == 'R') { R++; fr = true; } else if(s[i] == 'G') { G++; R--; if(R < 0) flg = false; fg = true; } else { if(!fr || !fg) flg = false; W++; if(G > 0) G--; } } if(R || G) flg = false; if(flg) cout << ok << endl; else cout << ng << endl; } }