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.
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).
op=""
l=[]
for io in range(0,3):
                line=input()
                l.append(line)
                op=op+line
a1=op[0]
a2=op[1]
a3=op[2]
b1=op[3]
b2=op[4]
b3=op[5]
c1=op[6]
c2=op[7]
c3=op[8]
if op.count("X")>5 or op.count("0")>4:
                print("illegal")
else:
                if op.count(".")>0:
                                if op.count("X")>=op.count("0"):
                                                print("second")
                                else:
                                                print("first")
                else:
                                if a1=="o" and a2=="o" and a3=="o":
                                    print("the second player won")
                                elif b1=="o" and b2=="o" and b3=="o":
                                    print("the second player won")
                                elif c1=="o" and c2=="o" and c3=="o":
                                    print("the second player won")
                                elif a2=="o" and a3=="o" and a1=="o":
                                    print("the second player won")
                                elif b2=="o" and b3=="o" and b1=="o":
                                    print("the second player won")
                                elif c2=="o" and c3=="o" and c1=="o":
                                    print("the second player won")
                                elif a1=="o" and a3=="o" and a2=="o":
                                    print("the second player won")
                                elif b1=="o" and b3=="o" and b2=="o":
                                    print("the second player won")
                                elif c1=="o" and c3=="o" and c2=="o":
                                    print("the second player won")
                                elif a1=="o" and b1=="o" and c1=="o":
                                    print("the second player won")
                                elif b1=="o" and c1=="o" and a1=="o":
                                    print("the second player won")
                                elif a1=="o" and c1=="o" and b1=="o":
                                    print("the second player won")
                                elif a2=="o" and b2=="o" and c2=="o":
                                    print("the second player won")
                                elif b2=="o" and c2=="o" and a2=="o":
                                    print("the second player won")
                                elif a2=="o" and c2=="o" and b2=="o":
                                    print("the second player won")
                                elif a3=="o" and b3=="o" and c3=="o":
                                    print("the second player won")
                                elif b3=="o" and c3=="o" and a3=="o":
                                    print("the second player won")
                                elif a3=="o" and c3=="o" and b3=="o":
                                    print("the second player won")
                                elif a1=="o" and b2=="o" and c3=="o":
                                    print("the second player won")
                                elif b2=="o" and c3=="o" and a1=="o":
                                    print("the second player won")
                                elif a1=="o" and c3=="o" and b2=="o":
                                    print("the second player won")
                                elif a3=="o" and b2=="o" and c1=="o":
                                    print("the second player won")
                                elif b2=="o" and c1=="o" and a3=="o":
                                    print("the second player won")
                                elif a3=="o" and c1=="o" and b2=="o":
                                    print("the second player won")
                                elif a1=="x" and a2=="x" and a3=="x":
                                    print("the first player won")
                                elif b1=="x" and b2=="x" and b3=="x":
                                    print("the first player won")
                                elif c1=="x" and c2=="x" and c3=="x":
                                    print("the first player won")
                                elif a2=="x" and a3=="x" and a1=="x":
                                    print("the first player won")
                                elif b2=="x" and b3=="x" and b1=="x":
                                    print("the first player won")
                                elif c2=="x" and c3=="x" and c1=="x":
                                    print("the first player won")
                                elif a1=="x" and a3=="x" and a2=="x":
                                    print("the first player won")
                                elif b1=="x" and b3=="x" and b2=="x":
                                    print("the first player won")
                                elif c1=="x" and c3=="x" and c2=="x":
                                    print("the first player won")
                                elif a1=="x" and b1=="x" and c1=="x":
                                    print("the first player won")
                                elif b1=="x" and c1=="x" and a1=="x":
                                    print("the first player won")
                                elif a1=="x" and c1=="x" and b1=="x":
                                    print("the first player won")
                                elif a2=="x" and b2=="x" and c2=="x":
                                    print("the first player won")
                                elif b2=="x" and c2=="x" and a2=="x":
                                    print("the first player won")
                                elif a2=="x" and c2=="x" and b2=="x":
                                    print("the first player won")
                                elif a3=="x" and b3=="x" and c3=="x":
                                    print("the first player won")
                                elif b3=="x" and c3=="x" and a3=="x":
                                    print("the first player won")
                                elif a3=="x" and c3=="x" and b3=="x":
                                    print("the first player won")
                                elif a1=="x" and b2=="x" and c3=="x":
                                    print("the first player won")
                                elif b2=="x" and c3=="x" and a1=="x":
                                    print("the first player won")
                                elif a1=="x" and c3=="x" and b2=="x":
                                    print("the first player won")
                                elif a3=="x" and b2=="x" and c1=="x":
                                    print("the first player won")
                                elif b2=="x" and c1=="x" and a3=="x":
                                    print("the first player won")
                                elif a3=="x" and c1=="x" and b2=="x":
                                    print("the first player won")