import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int n; readV(n); auto calc(string s) { auto r = 0, g = 0, w = 0; foreach_reverse (c; s) switch (c) { case 'R': ++r; break; case 'G': if (g == r) return false; ++g; break; case 'W': if (g == 0) return false; if (w < g) ++w; break; default: assert(0); } return r == g && g == w; } foreach (_; 0..n) { string s; readV(s); writeln(calc(s) ? "possible" : "impossible"); } }