human
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.

You are given a 3 × 3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below: 

  * illegal — if the given board layout can't appear during a valid game.

  * the first player won — if in the given board layout the first player has just won.

  * the second player won — if in the given board layout the second player has just won.

  * draw — if the given board layout has just let to a draw. 

Input

The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).

Output

Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.

Examples

Input

X0X
.0.
.X.

Output

second
Solve the task in PYTHON.

What is a Python program to find the player (first or second), whose turn is next, or print one of the verdicts below:?
assistant
#Here is Python program to find the player (first or second), whose turn is next, or print one of the verdicts below: 
.

import sys

def data_from_stdin():
    return [raw_input().strip() for i in range(3)]

input_data = data_from_stdin()

lines_and_diagonals = [
    [(0, 0), (0, 1), (0, 2)],
    [(1, 0), (1, 1), (1, 2)],
    [(2, 0), (2, 1), (2, 2)],

    [(0, 0), (1, 0), (2, 0)],
    [(0, 1), (1, 1), (2, 1)],
    [(0, 2), (1, 2), (2, 2)],

    [(0, 0), (1, 1), (2, 2)],
    [(0, 2), (1, 1), (2, 0)],
]

class Field(object):

    def __init__(self, lines):
        self.data = lines

        self._complete_lines = None
        self._winner = None

    
    def complete_lines(self):
        if self._complete_lines is not None:
            return self._complete_lines

        self._complete_lines = []

        for line in lines_and_diagonals:
            line_mark = None
            for row, column in line:
                current_mark = self.data[row][column]
                if current_mark == '.':
                    break
                if line_mark is None:
                    line_mark = current_mark
                    continue
                if line_mark != current_mark:
                    break
            else:
                self._complete_lines.append((line_mark, line))

        return self._complete_lines

    def is_legal(self):
        self._cross_count = sum(line.count('X') for line in self.data)
        self._zeros_count = sum(line.count('0') for line in self.data)

        if not (0 <= self._cross_count - self._zeros_count <= 1):
            return False

        complete_lines = self.complete_lines()

        if len(complete_lines) > 0:
            winner, _ = complete_lines[0]
            for line_winner, _ in complete_lines[1:]:
                if line_winner != winner:
                    return False
            if winner == 'X' and not (self._cross_count - self._zeros_count) == 1:
                return False
            elif winner == '0' and self._cross_count != self._zeros_count:
                return False
            self._winner = winner

        return True

    @property
    def...