#include #include #define FOR(i,a,b) for(int i=(a); i<(b); i++) using namespace std; int solve(string str){ // 最後から2本目より前のバスが走っている可能性のある系統の最大数 int max_n = 0; // 最後から一本目が走ったが、最後の一本は走っていない系統の数 int last = 0; FOR(j, 0, str.size()){ string c = str.substr(j, 1); if (c == "W"){ max_n++; } else if (c == "G"){ max_n --; if (max_n < 0) return 0; last += 1; } else{ last--; if (last < 0) return 0; } } // lastが0かつRで終わる場合のみあり得るパターン if (last == 0 && str.substr(str.size() - 1, 1) == "R"){ return 1; } else { return 0; } } int main(){ int t; cin >> t; FOR(i, 0, t){ string str; cin >> str; int if_possible = solve(str); if(if_possible){ cout << "possible" << endl; } else { cout << "impossible" << endl; } } return 0; }