#include #include using namespace std; int main() { int t, wcount = 0, gcount = 0, rcount = 0; char s[1001]; cin >> t; int miss = 0; for (int i = 1; i <= t; i++) { cin >> s; for (int j = strlen(s); j >= 0; j--) { if (s[j] == 'R') { rcount++; } if (s[j] == 'G') { if (rcount > 0) { gcount++; rcount--; } else { miss++; } } if (s[j] == 'W') { if (gcount > 0) { gcount--; wcount++; } else if (wcount > 0) { wcount++; } else { miss++; } } } if ((rcount != 0 || gcount != 0) || miss > 0) { cout << "impossible" << endl; } else { cout << "possible" << endl; } miss = 0; wcount = 0; gcount = 0; rcount = 0; } }