#include #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REPR(i, n) for(int i = (int)(n); i >= 0; i--) #define FOR(i, s, n) for (int i = (s); i < (int)(n); i++) #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; ll N, T, K, W, H, M, C, V; const int MAX = 510000; const int MOD = 1e9; const double PI=3.14159265358979323846; long long fac[MAX], finv[MAX], inv[MAX]; vector cx, cy, c; ll MM = 1e12; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } std::vector Eratosthenes(int n ){ std::vector is_prime( n + 1 ); for( int i = 0; i <= n; i++ ) is_prime[ i ] = true; std::vector P; for( int i = 2; i <= n; i++ ){ if( is_prime[ i ] ){ for( int j = 2 * i; j <= n; j += i ){ is_prime[ j ] = false; } P.emplace_back( i ); } } return P; } int main(){ cin >> N ; REP(i,N){ string str; cin >> str; int num = 0; int r = 0; int g = 0; int w = 0; bool flag = true; for(int i = str.size()-1; i >= 0; --i){ if( (r <= 0 or g <= 0) and str[i] == 'W'){ flag = false; } if(str[i] == 'W') ++w; if(str[i] == 'R') {++num; ++r;} if(str[i] == 'G'){ ++g; if(num > 0) --num; } } if(!num and g==r and flag and w >= g) cout << "possible"; else cout << "impossible"; cout << "\n"; } return 0; }