#include #include #include #include #include #include #include #include using namespace std; using ll = long long; const ll INF = 1e9; const ll MOD = 1e9 + 7; int main() { int T; cin >> T; for (int i = 0; i < T; i++) { string S; cin >> S; int w = 0, g = 0, r = 0; bool possible = true; for (int k = 0; k < S.length(); k++) { switch (S[k]) { case 'W': w++; break; case 'G': g++; if (w < g) possible = false; break; case 'R': r++; if (w < r || g < r) possible = false; break; } if (!possible) break; } if (((g == 0 || r == 0) && w > 0) || (g != r || w % g > 0 || w % r > 0)) { possible = false; } cout << (possible ? "possible" : "impossible") << endl; } return 0; }