/* -*- coding: utf-8 -*- * * 154.cc: No.154 市バス - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ /* typedef */ /* global variables */ /* subroutines */ /* main */ int main() { int tn; cin >> tn; while (tn--) { string s; cin >> s; bool ok = true, gf = false; int r = 0, g = 0; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == 'R') r++; else if (s[i] == 'G') { if (r == 0) { ok = false; break; } r--, g++, gf = true; } else if (s[i] == 'W') { if (! gf) { ok = false; break; } if (g > 0) g--; } } cout << (ok ? "possible" : "impossible") << endl; } return 0; }