#include #include #include #include using namespace std; bool can(const string &s) { string r = s; reverse(r.begin(), r.end()); while (r.length() > 1) { int pos = r.find('R', 1); if (pos < 0) { break; } r = r.substr(0, pos) + r.substr(pos + 1); pos = r.find('G', pos); if (pos < 0) { return false; } r = r.substr(0, pos) + r.substr(pos + 1); pos = r.find('W', pos); if (pos < 0) { return false; } r = r.substr(0, pos) + r.substr(pos + 1); } if (r.length() < 3 || r[0] != 'R' || r[1] != 'G') { return false; } for (int i = 2; i < (int)r.length(); ++i) { if (r[i] != 'W') { return false; } } return true; } int main(int argc, char *argv[]) { string s; getline(cin, s); int T = atoi(s.c_str()); for (int i = 0; i < T; ++i) { getline(cin, s); cout << (can(s) ? "possible" : "impossible") << endl; } return 0; }