#K76492. Detect Contiguous All-Ones Submatrix

    ID: 34654 Type: Default 1000ms 256MiB

Detect Contiguous All-Ones Submatrix

Detect Contiguous All-Ones Submatrix

You are given an integer n and an n × n matrix consisting of 0s and 1s. Your task is to determine whether there exists a contiguous submatrix of size at least 2 × 2 that is entirely composed of 1s.

A contiguous submatrix is a block of adjacent cells in the original matrix. In this problem, you only need to check for the existence of at least one 2 × 2 block where every element is 1.

The condition for a valid submatrix can be expressed in LaTeX as follows:

$$\text{For some } i, j:\; \forall r \in \{0,1\},\; \forall c \in \{0,1\},\; A[i+r][j+c] = 1.$$

Output "YES" if such a submatrix exists and "NO" otherwise.

inputFormat

The first line of input contains a single integer T representing the number of test cases. The description of each test case is as follows:

  1. The first line contains an integer n --- the size of the matrix.
  2. The next n lines each contain n integers (either 0 or 1), separated by spaces, representing the rows of the matrix.

Input is given via stdin.

outputFormat

For each test case, output a single line containing either "YES" if the matrix contains a contiguous 2 × 2 submatrix of all 1s, otherwise "NO".

Output should be printed to stdout.

## sample
1
3
1 0 1
0 1 0
1 0 1
NO

</p>