#include #include #include using namespace std; bool possible(const string& s) { int gCount = 0; for (size_t i = 0; i < s.size(); ++i) { char ch = s[i]; if (ch == 'G') { ++gCount; } else if (ch == 'R') { if (gCount == 0) { return false; } --gCount; } } if (gCount != 0) { return false; } int rootCount = 0; int whiteCount = 0; for (int i = s.size() - 1; i >= 0; --i) { char ch = s[i]; if (ch == 'R') { ++rootCount; } else if (ch == 'W') { if (rootCount == 0) { return false; } whiteCount = min(rootCount, whiteCount + 1); } } if (whiteCount != rootCount) { return false; } return true; } int main() { int t; cin >> t; for (int i = 0; i < t; ++i) { string s; cin >> s; cout << (possible(s) ? "possible" : "impossible") << endl; } return 0; }