#include #include #include using namespace std; string solve(string str){ # define OK "possible" # define NG "impossible" regex re("^W+"); reverse(str.begin(), str.end()); while(!str.empty()){ if(str[0] != 'R') return NG; str.replace(0, 1, ""); int g_index = str.find("G"); if(g_index == -1) return NG; str.replace(g_index, 1, ""); int w_index = str.find("W"); if(w_index == -1) return NG; str.replace(w_index, 1, ""); str = regex_replace(str, re, "", regex_constants::format_first_only); } return OK; } int main(){ int n; cin >> n; for(int i=0; i> str; cout << solve(str) << endl; } }