SP28450 ADAPATH - Ada and Path

Description

Ada the Ladybug loves Crosswords, Sudoku's and all other similar games. She has found an interesting game in the latest issue of Magazine Bug. The game is simple - you will be given a square full of numbers. Each number must be part of exactly one path. Path must begin at number **1** and can only continue to neighboring number (left,right,up,down), which is larger by 1. Ada's friend is working as a director of Magazine Bug. He wants to surprise her and add few more games to following issues of the magazine. Anyway, he wants you to check, whether the games are valid (i.e. if all the numbers can be part of a path).

Input Format

The first line will contain **T**, the number of test-cases. Then **T** test-cases follow, each beginning with an integer **1 , the size of the game board.** Afterward, **N** lines follow with **N** integers **1**

Output Format

For each test-case print either "**YES**" if board is valid or "**NO**" if it isn't.