OVOXO - Tic-tac-toe 3

no tags 

Bored to death working at the Byteland Office...your colleagues have resorted to game of crosses Xs and noughts Os or Tic-tac-toe. One of them keeps on losing and is tired of the jokes. He plans to have an Android app in his phone to help him out. He is your good friend and seeks your assistance. "Treat at ANC is guaranteed", he says.

He also is very frugal when it comes to memory usage. So please don't write a long if else chain... because you have to do the task within 999 bytes.

Input

An integer T - the number of test cases. (T < 1000). T test cases follow.

Each test case comprises 3 strings each separated by newline and containing exactly 3 characters (either 'X','O' or '_') per line. An empty line follows each test case. Each input position is guaranteed to be a valid tic-tac-toe position such that the game is still not over.

Output

For each test case print "WON" if it is a sure shot winning position, else print "CONTINUE". Then output the game after having made your move. If more than one move are equally good try playing the move on the first empty spot.

Example

Input:
2
OOX
OX_
__X

XX_
XOO
_O_

Output:
WON
OOX
OXX
__X
WON
XXX
XOO
_O_

Info

  1. X always moves first (it is the standard) and whose move it currently is can be computed.
  2. Winning position is meant for the current player.
  3. Winning in fewer moves is better, and drawing is better than losing as in general AI.
  4. You need to print the board as it looks after making the best move.
  5. Print WON if the current player can win in the case when both players play optimally from here on.

hide comments

Added by:Aditya Pande
Date:2013-01-14
Time limit:1s
Source limit:999B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:TOE2