#include #include #include #include #include #include using namespace std; int main() { int t, w, g, r; string s; cin >> t; vector ans(t, false); for (int i = 0; i < t; i++) { cin >> s; int n = s.size(); bool isPossible; w = g = r = 0; for (int i = 0; i < n; i++) { isPossible = true; if (s[i] == 'W') { w++; } else if (s[i] == 'G') { g++; if (w < g) { isPossible = false; break; } } else if (s[i] == 'R') { r++; if (w < r || w < r) { isPossible = false; break; } } } if (r == 0 || r != g || s[n - 1] != 'R') { isPossible = false; } ans[i] = isPossible; } for (int i = 0; i < t; i++) { cout << (ans[i] ? "possible" : "impossible") << endl; } return 0; }