#include #include #include bool check(const std::string& l) { using std::size_t; if (l.size() < 3 || 'R' != l.back()) return false; size_t r = l.size() - 1; size_t g = l.find_last_of('G', l.size() - 2); size_t w = l.find_last_of('W', g); while ( std::string::npos != r && 0 != r && std::string::npos != g && 0 != g//Rより前にGがあるか && std::string::npos != w && 0 != w//Gより前にWがあるか ) { r = l.find_last_of('R', r - 1); g = l.find_last_of('G', std::min(g - 1, r)); w = l.find_last_of('W', std::min(w - 1, g)); } return (0 == w || (std::string::npos == r && std::string::npos == l.find_last_of('G', w - 1))); } int main() { const auto n = []() { std::string buf; std::getline(std::cin, buf); return static_cast(std::stoul(buf)); }(); std::string buf; const char* re[] = { "impossible", "possible" }; for (std::size_t i = 0; i < n && std::getline(std::cin, buf); ++i) { const auto r = check(buf.substr(0, buf.find_last_not_of('\n') + 1)); std::cout << re[r] << std::endl; } }