#include using namespace std; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define rep(i,a,b) for (int i = (a); i < (b); i++) #define rrep(i,a,b) for (int i = (b)-1; i >= (a); i--) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) #define fst first #define snd second #define DUMP( x ) cerr << #x << " = " << ( x ) << endl typedef long long ll; // ------------------------------------- void Main() { string s; cin >> s; map co; bool ok = 1; int lw=-1,lg=-1; rep(i, 0, SZ(s)) { char c = s[i]; co[c]++; if (co['W'] < co['G'] || co['G'] < co['R']) { ok = 0; break; } if (c == 'G') lg = i; if (c == 'W') lw = i; } if (co['G'] != co['R']) { ok = 0; } if (lg < lw) ok = 0; puts(ok ? "possible" : "impossible"); } int main() { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; while (T--) Main(); return 0; }