#define _CRT_SECURE_NO_WARNINGS //#define _GLIBCXX_DEBUG #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i ostream & operator<<(ostream & os, vector const &); template typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple const &){} template typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple const & t){ os << (n==0?"":" ") << get(t); _ot(os, t); } template ostream & operator<<(ostream & os, tuple const & t){ _ot<0>(os, t); return os; } template ostream & operator<<(ostream & os, pair const & p){ return os << "(" << p.first << ", " << p.second << ") "; } template ostream & operator<<(ostream & os, vector const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; } #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "< pq; string s; bool check1(pq w, pq g, pq r){ if(r.size()==0 || g.size()==0) return false; if(r.size() != g.size()) return false; while(1){ int a,b,c; if(min({w.size(),g.size(),r.size()})==0){ break; } tie(a,b,c) = tie(w.top(),g.top(),r.top()); a=-a, b=-b, c=-c; dump(a,b,c); w.pop(),g.pop(),r.pop(); if(a < b && b < c) continue; return false; } bool ok = true; if(g.size() || r.size()) ok = false; int n=s.size(); if(s[n-1]=='W') return false; if(s[n-2]=='W') return false; return ok; } int main(){ #ifdef LOCAL freopen("in","r",stdin); #endif int n; cin >> n; rep(_,n){ cin >> s; dump(s); pq r,g,w; rep(i,s.size()){ if(s[i]=='R') r.push(-i); if(s[i]=='G') g.push(-i); if(s[i]=='W') w.push(-i); } bool ok = check1(w,g,r); puts(ok ? "possible" : "impossible"); } }