#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; using Data = pair>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; int check(string s) { int cnt1 = 0; rep(i, 0, s.size()) { if (s[i] == 'G')cnt1++; else if (s[i] == 'R')cnt1--; if (cnt1 < 0)return false; } if (cnt1 != 0)return false; int cnt2 = 0; rep(i, 0, s.size()) { if (s[i] == 'W')cnt2++; else if (s[i] == 'G') { cnt2--; } if (cnt2 < 0)return false; } reverse(all(s)); int f = 0; rep(i, 0, s.size()) { if (s[i] == 'G')f = 1; if (s[i] == 'W' && f == 0)return false; } return true; } int main() { int n; cin >> n; rep(i, 0, n) { string s; cin >> s; if (check(s))cout << "possible" << endl; else cout << "impossible" << endl; } return 0; }