QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#13823. Matrix Game

統計

Xiao Q is a very clever child. Besides chess, he also enjoys playing a computer puzzle game called "Matrix Game." The game is played on an $N \times N$ black-and-white square grid (similar to a chessboard, but the colors are arbitrary). You can perform two types of operations on the matrix:

  • Row swap operation: Choose any two rows of the matrix and swap them (i.e., swap the colors of the corresponding cells).
  • Column swap operation: Choose any two columns of the matrix and swap them (i.e., swap the colors of the corresponding cells).

The goal of the game is to perform a sequence of operations such that all cells on the main diagonal (the line from the top-left corner to the bottom-right corner) of the square grid are black.

For some levels, Xiao Q is completely stumped, leading him to suspect that these levels might be unsolvable! Therefore, Xiao Q has decided to write a program to determine whether these levels have a solution.

Input

The first line contains an integer $T$, representing the number of test cases.

Each test case starts with an integer $N$, representing the size of the square grid. The next $N$ lines contain an $N \times N$ binary matrix (where $0$ represents white and $1$ represents black).

Output

The output should contain $T$ lines. For each test case, if the level has a solution, output Yes; otherwise, output No.

Constraints

  • For 20% of the data, $N \le 7$.
  • For 50% of the data, $N \le 50$.
  • For 100% of the data, $N \le 200$.

Examples

Input 1

2
2
0 0
0 1
3
0 0 1
0 1 0
1 0 0

Output 1

No
Yes

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.