s//123 456 789 z147,258,369,159,357/;{/z/;print$`,$p=$p^h?X:O;/(.)\1\1/?die$1:/\d/||die Tie;$?=<>until s/$?/$p/g;redo}