#include #include using namespace std; int main() { bool tmp2; int T, tmp1, tmp3, j; string S; cin >> T; for (int i = 0; i < T; ++i) { cin >> S; tmp1 = 0; tmp2 = false; tmp3 = 0; for (j = 0; j < S.size(); ++j) { if (S[j] == 'W') { ++tmp1; tmp2 = true; } else if (S[j] == 'G') { if (tmp1 == 0) break; --tmp1; tmp2 = false; ++tmp3; } else { if (tmp3 == 0) break; --tmp3; } } if (j != S.size() || tmp2 || tmp3) cout << "impossible"; else cout << "possible"; cout << endl; } }