#include using namespace std; typedef long long ll; typedef vector VI; typedef vector VVI; typedef vector VL; typedef vector VVL; typedef pair PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MOD 1000000007 #define INF (1LL<<25) //33554432 #define PI 3.14159265359 #define EPS 1e-12 //#define int ll signed main(void) { int t; string s[1010]; cin >> t; REP(i, t) cin >> s[i]; REP(i, t) { stack a; while(a.size()) a.pop(); bool w = false, g = false, r = false; int ww = INF, gg = INF, www = 0; REP(j, s[i].size()) { if(s[i][j] == 'G') { www--; if(www < 0) { a.push('A'); break; } a.push('G'); g = true; gg = j; } else if(s[i][j] == 'R') { r = true; if(a.size() && a.top() == 'G') { a.pop(); } else { a.push('a'); break; } } else if(s[i][j] == 'W') { w = true; ww = j; www++; } } if(a.empty() && g && w && r && ww < gg) { cout << "possible" << endl; } else { cout << "impossible" << endl; } } return 0; }