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