<>; for(<>){ $W=$G=$R=$|=0; ++$$_,$||=/G/?!$W--:/R/&&!$G--for/./g; print$||!y/GR//|/WR*$/|/G$/?im:'',possible,$/ }