import java.util.Scanner;

public class TicTacToe_002 {
	public static void main(String[] args) {
		char[][] board = {{'#','#','#'},
				{'#','#','#'},
				{'#','#','#'}};

		Scanner in = new Scanner(System.in);

		boolean turn;
		boolean draw;
		boolean win;

		turn = false; // If turn = true here x will move first; otherwise it will move second.
		draw = false;
		win = false;
		
		printBoard(board);
		Move m = null;
		
		while(true) {
			if (turn) {
				//m = computer_move2(board,  m);  // Newell and Simon's computer: x
				m = computer_move(board);  // random computer: x
			}
			else {
				m = new Move(in.nextInt(), in.nextInt());
				while (!isValidMove(board, m)) {
					m.row = in.nextInt();
					m.col = in.nextInt();
				}

			}
			board[m.row][m.col] = (turn ? 'x' : 'o');

			printBoard(board);

			if (win(board, m)) {
				win = true;
				break;
			}
			if (draw(board)) {
				draw = true;
				break;
			}
			turn = !turn;
		}
		
		if (draw) {
			System.out.println("draw");
		}
		if (win) {
			System.out.println((turn ? "x" : "o") + " wins!");
		}

		in.close();
	}

	public static void printArray(char[][] a) {
		for (int row = 0; row < 3; row++) {
			for (int col = 0; col < 3; col++) {
				System.out.print(a[row][col] + " ");
			}
			System.out.println();
		}
	}

	public static void printBoard(char[][] board) {
		System.out.println();
		printArray(board);
		System.out.println();
	}

	public static Move computer_move(char[][] board) {
		Move m = new Move(1,1);
		while (!isValidMove(board, m)) {
			m.row = (int)(Math.random() * 3);
			m.col = (int)(Math.random() * 3);
		}
		return m;
	}

	/** Newell and Simon's algorithm */
	public static Move computer_move2(char[][] board, Move pm) {
		char[][] boardCopy = copyBoard(board);
		Move m = new Move(1,1);

		if (pm == null) return m;  // Save some time, if we are the first player.

		char otherPlayer = board[pm.row][pm.col];
		char player = (otherPlayer == 'x' ? 'o' : 'x');

		// 1. Do I have 2 in a line?
		
		// 2. Does my opponent have 2 in a line?
		
		// 3. Can I fork my opponent?
		
		// 4. Can my opponent fork me?
		
		// 5. Is the center open?
		
		// 6. Did my opponent move in a corner?  If so, move in the opposite corner.
		
		// 7. Is there an empty corner?
		
		// 8. Otherwise, move on a side middle.
		
		return computer_move(board);  // This won't happen once all 8 rules are implemented.
	}

	public static boolean isValidMove(char[][] board, Move m) {
		boolean valid = true;
		if (m.row > 2 || m.row < 0) valid = false;
		if (m.col > 2 || m.col < 0) valid = false;
		if (board[m.row][m.col] != '#') valid = false;
		return valid;
	}

	/** This method should be called if win() returns false */
	public static boolean draw(char[][] board) {
		boolean draw = true;
		for (char[] row : board) {
			for (char c : row) {
				if (c == '#') draw = false;
			}
		}
		return draw;
	}

	public static boolean win(char[][] board, Move m) {
		boolean win = false;

		// BLANK_0
		
		return win;
	}

	public static char[][] copyBoard(char[][] b) {
		char[][] a = new char[3][3];
		for (int row = 0; row < 3; row++) {
			for (int col = 0; col < 3; col++) {
				a[row][col] = b[row][col];
			}
		}
		return a;
	}
}