#include #include using namespace std; string s; bool replace_before(char c, char c2, int n) { for(int i = n - 1; i >= 0; i--) { if (s[i] == c) { s[i] = '#'; return true; } } return false; } int main() { int T; cin >> T; for(int t = 0; t < T; t++) { cin >> s; if (s[s.length() - 1] != 'R') { cout << "impossible" << endl; continue; } bool ok = true; bool extra_w = false; for (int i = 0; i < s.length(); i++) { if (s[i] == 'W') extra_w = true; if (s[i] == 'G') { extra_w = false; if (!replace_before('W', 'w', i)) { ok = false; break; } } if (s[i] == 'R') { if (!replace_before('G', 'g', i)) { ok = false; break; } } } if (ok && !extra_w) cout << "possible" << endl; else cout << "impossible" << endl; } }