import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.array; import std.typecons; import std.random; bool cityBus(string s, int[] routes = []){ if(!s.length) return routes.reduce!min >= 3; auto tail = s.back.to!char; s = s[0..$-1]; /// ***R -------------------------- if(tail == 'R'){ return cityBus(s, routes ~= 1); } /// ****G ------------------------ else if(tail == 'G'){ foreach(ref r; routes){ if(r == 1){ r += 1; return cityBus(s, routes); } } return false; } /// ***W ----------------------- else{ foreach(ref r; routes){ if(r == 2){ r += 1; return cityBus(s, routes); } } foreach(ref r; routes){ if(r > 2){ r += 1; return cityBus(s, routes); } } return false; } } void main(){ immutable N = readln.strip.to!int; foreach(i; 0..N) writeln( cityBus(readln.strip) ? "possible" : "impossible" ); }