#include <iostream>
using namespace std;

int T;
string S;

/*
 * ありえないケースは
 * (1) w_cnt < g_cnt
 * (2) w_cnt < r_cnt
 * (3) g_cnt < r_cnt
 * (4) 全て終わったあとに g_cnt != r_cnt
 * (5) 最後のWが出てから一度もGが出てきていない場合
 */
void Solve() {
    int w_cnt = 0, g_cnt = 0, r_cnt = 0;
    bool not_terminated = false;

    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'W') {
            w_cnt++;
            not_terminated = true;
        } else if (S[i] == 'G') {
            g_cnt++;
            not_terminated = false;
        } else {
            r_cnt++;
        }
        if (w_cnt < g_cnt || w_cnt < r_cnt || g_cnt < r_cnt) {
            cout << "impossible" << endl;
            return;
        }
    }
    if (!not_terminated && g_cnt == r_cnt) cout << "possible" << endl;
    else cout << "impossible" << endl;
}

int main() {
    cin >> T;

    while (T--) {
        cin >> S;

        Solve();
    }

    return 0;
}