Puzzle

3.5

2 votes
Easy-Medium
Problem

My friend Bob loves to resolve sudokus. A sudoku is a numeric puzzle formed by a grid of nn, divided in n grids of nn . Every row, column and grid must contain all the numbers from 1 to n, without repeat. Bob can resolve 20 sudokus per day, the problem is that 19 of them are wrong. Can you make a program that given the solutions found by Bob tell him if they are wrong or right?

Input

The first line of input contains a integer t, the number of test cases. Each case begins with an integer n (1n25), it is guaranteed that n have an integer square root. This line is followed by n lines, each one with n numbers mi,j separated by a blank space (1mi,jn, with 1i,jn).

Output

For each test case prints a single line with the word “yes” if the sudoku has been resolved correctly or “no” otherwise.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?