#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; while (T--) { string s; cin >> s; int n = s.length(); int w = 0; int g = 0; int r = 0; bool ok = true; bool flag = false; for (int i = 0; i < n; i++) { if (s[i] == 'W') { w++; } else if (s[i] == 'G') { if (w == 0) { ok = false; break; } g++; w--; } else { flag = true; if (g == 0) { ok = false; break; } r++; g--; } } if (!flag) { ok = false; } /* if (!(w == 0 && g == 0 && r == 0)) { ok = false; } */ if (!ok) { cout << "impossible" << '\n'; } else { cout << "possible" << '\n'; } } return 0; }