#include using namespace std; int T, N; string S; bool rec(int number = 0){ if(number == N) return true; int r = 0, m = 0, n = 0; int flag = false; if((r = S.find("W")) != string::npos && r < S.size()){ if((m = S.find("G", r)) != string::npos && m < S.size()){ if((n = S.find("R", m)) != string::npos && n < S.size()){ S.erase(S.begin() + r); S.erase(S.begin() + (m - 1)); S.erase(S.begin() + (n - 2)); flag = rec(number + 1); } } } return flag; } int main(void){ cin >> T; int i, j, k, p; for(i = 0; i < T; ++i){ cin >> S; j = k = p = 0; while((p = S.find("G", p)) != string::npos && p <= S.size()){ ++j; ++p; } p = 0; while((p = S.find("R", p)) != string::npos && p <= S.size()){ ++k; ++p; } if(j != k){ cout << "impossible" << endl; } else{ N = j; k = 0; for(j = S.size(); j >= 0; --j){ if(S[j] == 'W') ++k; if(k == N) break; } S.erase(S.begin(), S.begin() + (j - 1)); if(rec()){ cout << "possible" << endl; } else cout << "impossible" << endl; } } return 0; }