#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(int i=(a);i<(b);++i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define MOD 1000000007 int main(){ int n; cin>>n; rep(i,0,n){ string s; cin>>s; int a1,b1,c1; a1 = count(all(s),'W'); b1 = count(all(s),'G'); c1 = count(all(s),'R'); if(b1!=c1){ cout << "impossible" << endl; continue; } if(a1 < b1){ cout << "impossible" << endl; continue; } string ss = s; reverse(all(ss)); cout << ss << endl; int flag = 0; int flag1 = 0; rep(i,0,ss.sz){ if(flag == 0 && (ss[i] == 'W' || ss[i] == 'G')){ cout << "impossible" << endl; flag1 = 1; break; } else if(flag == 1 && ss[i] == 'W'){ cout << "impossible" << endl; flag1 = 1; break; } else if(flag == 0 && ss[i] == 'R'){ flag = 1; } else if(flag == 1 && ss[i] == 'G'){ flag = 2; break; } } string s1; rep(j,0,s.sz){ if(s[j]!='W'){ s1+=s[j]; } } int c = 0; int index1 = 0; int index2 = 0; if(flag1 == 0){ for(;;){ if(index1==s1.sz||index2==s1.sz){ cout << "impossible" << endl; break; } if(index1>index2){ cout << "impossible" << endl; break; } if(s1[index1]=='G'&&s1[index2]=='R'){ c++; if(c*2==s1.sz){ cout << "possible" << endl; break; } index1++; index2++; } else if(s1[index2]!='R'){ index2++; } else{ index1++; } } } } return 0; }