Problem: Bob has a grid with rows and columns, each of which contains either or for some integer . For example, one possible grid for is shown below:
Alice and Bob play a game as follows:
- Bob shows Alice his grid.
- Alice gives Bob an array of her choosing, whose elements are all or .
- Bob substitutes these values into his grid to make a grid of s and s.
- Bob sorts the elements of each column in non-decreasing order.
- Alice wins if all the elements in the middle row are ; otherwise, Bob wins.
For example, suppose Alice gives Bob the array for the grid above. Then the following will happen (colors are added for clarity):
Since the middle row is all , Alice wins.
Given Bob's grid, determine whether or not Alice can choose the array to win the game.
Input Format: The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the number of columns of Bob's grid.
The next three lines each contain integers, the -th of which contains (, ), representing Bob's grid.
If cell is in the input, that cell in Bob's grid should contain ; if is in the input, that cell in Bob's grid should contain . See the sample input and notes for a better understanding.
Output Format: For each test case, output "YES" (without quotes) if Alice can win, and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes", and "Yes" will be recognized as a positive response).
Note: The first test case is described in the statement.
In the second test case, Bob's grid is as follows:
For the last column to have in the middle row when sorted, Alice must pick . However, it is then impossible to choose such that the first column has in the middle when sorted. Thus, Alice cannot win.
In the third test case, Alice can pick .