#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; 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 { if (g == 0) { ok = false; break; } r++; g--; } } if (ok) { w = 0; g = 0; r = 0; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'R') { r++; } else if (s[i] == 'G') { if (r == 0) { ok = false; break; } g++; r--; } else { if (g == 0) { ok = false; break; } g--; w++; } } } if (s[n - 1] != 'R' || s[0] != 'W') { ok = false; } if (!ok) { cout << "impossible" << '\n'; } else { cout << "possible" << '\n'; } } return 0; }