#include #include #include #include using namespace std; bool solve(string s) { const int n = s.size(); int W = 0; int WW = 0; int G = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') { W++; WW++; } else if (s[i] == 'G') { WW = 0; W--; G++; } else { G--; } if (W < 0 || G < 0) return false; } return G == 0 && WW == 0; } int main() { int T; cin >> T; while (T--) { string s; cin >> s; cout << (solve(s) ? "possible" : "impossible") << endl; } }