#include #include using namespace std; int main() { int T; cin>>T; while (T--) { string s; cin>>s; int n=s.size(); const string possible="possible"; const string impossible="impossible"; string res=possible; vector bus; for(int i=n-1; i>=0; --i) { char c=s[i]; if (c=='R') { bus.push_back("R"); } else if (c=='G') { bool ok=false; for(auto& b: bus) if (b.back()=='R') { b+=c; ok=true; break; } if (!ok) res=impossible; } else { bool ok=false; for(auto& b: bus) if (b.back()=='G') { b+=c; ok=true; break; } if (!ok) { for(auto& b: bus) if (b.back()=='W') { ok=true; break; } } if (!ok) res=impossible; } } for(auto& b: bus) if (b!="RGW") res=impossible; cout<