#include #include #include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) typedef long long ll; using namespace std; int inputValue(){ int a; cin >> a; return a; }; template void output(T a, int precision) { if(precision > 0){ cout << setprecision(precision) << a << "\n"; } else{ cout << a << "\n"; } } int main() { // source code int N = inputValue(); rep(i, N){ string s; cin >> s; bool pos = true; bool wflag = false; int check = 0; int w = 0; int g = 0; int r = 0; rep(j, s.size() - 1){ if (s[j] == 'W') { w++; wflag = true; } else if (s[j] == 'G'){ g++; check++; wflag = false; } else{ r++; check--; if (check < 0) { pos = false; break; } } } if (s[s.size() - 1] != 'R') { pos = false; } else{ r++; check--; if (g != r || w < r || check != 0 || wflag) { pos = false; } } output(pos ? "possible" : "impossible", 0); } return 0; }