CF2008B.Square or Not

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Square or Not

A beautiful binary matrix is a matrix that has ones on its edges and zeros inside.

Examples of four beautiful binary matrices.

Today, Sakurako was playing with a beautiful binary matrix of size r×cr \times c and created a binary string ss by writing down all the rows of the matrix, starting from the first and ending with the rr-th. More formally, the element from the matrix in the ii-th row and jj-th column corresponds to the ((i1)c+j)((i-1)*c+j)-th element of the string.

You need to check whether the beautiful matrix from which the string ss was obtained could be squared. In other words, you need to check whether the string ss could have been build from a square beautiful binary matrix (i.e., one where r=cr=c).

Input

The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (2n21052 \le n \le 2 \cdot 10^5) — the length of the string.

The second line of each test case contains the string ss of length nn. The string is always the result of writing out the strings of a beautiful matrix.

It is guaranteed that the sum of nn across all test cases does not exceed 21052 \cdot 10^5.

Output

Print "Yes", if the original matrix could have been square, and "No" otherwise.

Note

For the second test case, string 1111 can be obtained from the matrix:

11
11

For the third test case, string 111101111 can be obtained from the matrix:

11
11 00 11
11

There is no square matrix in the fourth case, such that the string can be obtained from it.

Samples

5
2
11
4
1111
9
111101111
9
111111111
12
111110011111
No
Yes
Yes
No
No

在线编程 IDE

建议全屏模式获得最佳体验