<>;map{1while s/W([^W]*)G([^G]*)R$/$1$2/;print"im"x/[GR]/,possible,$/}<>