TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

The TTT(tic-tac-toe, also knows as ooxx) world final has begun. We all know that a 3x3 tic-tac-toe is too easy to draw, so this time we are playing a 4x4 game. 4x4 tic-tac-toe is played on a board with four rows and four columns. There are two players, x and o, who move alternately with x always going first. The game is won by the first player to get four of his or her pieces on the same row, column, or diagonal. If the board is full and neither player has won then the game is a draw.

Assuming that it is x's turn to move, x is said to have a forced win if x can make a move such that no matter what moves o makes for the rest of the game, x can win. This does not necessarily mean that x will win on the very next move, although that is a possibility. It means that x has a winning strategy that will guarantee an eventual victory regardless of what o does.

Your job is to write a program that, given a partially-completed game with x to move next, will determine whether x has a forced win. You can assume that each player has made at least one move, that the game has not already been won by either player, and that the board is not full.

Input Format

The input contains several test cases. The first line is a integer T <= 20 indicate the number of test cases. Each test case begins with a line containing a question mark and is followed by four lines representing the board; formatting is exactly as shown in the example. The characters used in a board description are the period (representing an empty space), lowercase x, and lowercase o.

Output Format

Each test case output a line. It output "YES" if there is a winning strategy for player x. If there is no such winning strategey for player x, output "NO" instead.

Sample Input 1

2
?
....
.xo.
.ox.
....
?
o...
.ox.
.xxx
xooo

Sample Output 1

NO
YES

Hints

The problem is ooxx, and so is the judge.

Problem Source

Migrated from old NTUJ.

Mid-Central USA 1999

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 65536 200