#include "bits/stdc++.h" using namespace std; bool check(string S){ vector count(3); bool flag = true; int pp = 0; for (int i = S.size() - 1; i >= 0; i--) { int r = 0; if (S[i] == 'G') r = 1; if (S[i] == 'R') r = 2; count[r]++; if (count[0] != 0 && count[1] == 0) return false; if (count[0] != 0 && count[2] == 0) return false; if (count[2] < count[1]) return false; if (r == 0) pp = min(pp + 1, count[1]); } if (count[2] != count[1]) return false; if (count[0] < count[1]) return false; return true; } int main() { int N; cin >> N; for (int t = 0; t < N; t++) { string S; cin >> S; if (check(S)) cout << "possible" << endl; else cout << "impossible" << endl; } }