#include #define EM 1000000 using namespace std; using LL = long long; using P = pair; LL LINF = 1e18; int INF = 1e9; LL mod = 1e9+7; using vint = vector; using vLL = vector; using vvint = vector>; using vvLL = vector>; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main(){ int T; cin >> T; for(int i = 0;i < T;i++){ string s; cin >> s; bool ans = true; int w = 0, g = 0, r = 0, cnt = 2; for(int j = 0;j < s.size();j++){ if(s[j] == 'W'){ w++; cnt = 2; }else if(s[j] == 'G'){ g++; if(g > w) ans = false; if(cnt == 2) cnt--; }else{ r++; if(r > g) ans = false; if(cnt == 1) cnt--; } } if(r != g || g == 0 || cnt != 0) ans = false; if(ans) cout << "possible" << endl; else cout << "impossible" << endl; } }