#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) #define FOR(i,a,b) for(ll i = (a);i<(b);i++) #define REP(i,a) FOR(i,0,(a)) #define MP make_pair bool check(string str){ int w = 0, g = 0, r = 0; bool flag = true; for(int i = 0;i < str.size();i++){ if(str[i] == 'W'){ flag = true; w++; }else if(str[i] == 'G'){ flag = true; if(w < g + 1) return false; g++; }else{ flag = false; if(w < r + 1 || g < r + 1) return false; r++; } } if(flag) return false; if(g != r) return false; return true; } int main() { int n; string str; cin >> n; for(int i = 0;i < n;i++){ cin >> str; bool ans = check(str); if(ans) cout << "possible" << endl; else cout << "impossible" << endl; } return 0; }