#include #define LL long long #define ULL unsigned long long #define REP(i,n) for(int i=0; i<(n); i++) #define REP2(i,x,n) for(int i=x; i<(n); i++) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; string S; REP( i, N ) { cin >> S; //reverse(S.begin(), S.end()); //1つも無い場合 if( S.find_first_of( 'R' ) == string::npos || S.find_first_of( 'G' ) == string::npos || S.find_first_of( 'W' ) == string::npos ) { cout << "impossible" << endl; continue; } //最後のG以降にWが有る場合 auto pos = S.find_last_of( 'G' ); if( S.find( 'W', pos ) != string::npos ) { cout << "impossible" << endl; continue; } //最後のR以降にGが有る場合 pos = S.find_last_of( 'R' ); if( S.find( 'G', pos ) != string::npos) { cout << "impossible" << endl; continue; } //最初のG以前にRが有る場合 bool flag = true; REP( i, (int)S.find( 'G' ) ) { if( S[i] == 'R' ) { cout << "impossible" << endl; flag = false; break; } } if( !flag ){ continue; } //GとRの数が等しく無い場合 int countG{},countR{}; REP( i, (int)S.size() ) { if( S[i] == 'G' ) { countG++; } if( S[i] == 'R') { countR++; } } cout << ( (countG > 0 && countR > 0 && countG == countR ) ? "possible" : "impossible" ) << endl; } return 0; }