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) { auto s = readln.chomp; writeln(calc(s) ? "possible" : "impossible"); } } bool calc(string s) { auto a = 0, b = 0, c = 0, d = 0; foreach_reverse (t; s){ switch (t) { case 'R': a += 1; b += 1; break; case 'G': c += 1; b -= 1; if (b < 0) return false; break; case 'W': d += 1; if (c < 0) return false; break; default: } } return a <= d; }