import std.algorithm, std.array, std.container, std.range; import std.numeric, std.math, std.bigint, std.bitmanip, std.random; import std.string, std.conv, std.stdio, std.typecons; void main() { auto t = readln.chomp.to!int; foreach (_; 0..t) writeln(calc(readln.chomp) ? "possible" : "impossible"); } bool calc(string s) { auto a = 0, b = 0, c = false, d = 0; foreach_reverse (t; s) { switch (t) { case 'R': a += 1; break; case 'G': b += 1; c = true; d -= 1; if (a < b) return false; break; case 'W': if (!c) return false; else if (d < 0) d += 1; break; default: assert(0); } } return (a == b && d == 0); }