#include #include #include #include bool solve(const std::string& s) { int cntR{}, cntG{}, cntW{}; for (const auto c : s) { if (c == 'R') { cntR++; } if (c == 'G') { if (cntR >= 1) { cntG++; cntR--; } else { return false; } } if (c == 'W') { if (cntG >= 1) { cntW++; cntG--; } else if (cntW >=1) { cntW++; } else { return false; } } if (cntR == 0 && cntG == 0) { return true; } } return false; } int main(int argc, char const* argv[]) { int T; std::cin >> T; std::vector s(T); for (int i = 0; i < T; i++) { std::cin >> s[i]; std::reverse(s[i].begin(), s[i].end()); } for (int i = 0; i < T; i++) { std::cout << (solve(s[i]) ? "possible" : "impossible") << std::endl; } return 0; }