CF2069A.Was there an Array?

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

Was there an Array?

For an array of integers a1,a2,,ana_1, a_2, \dots, a_n, we define its equality characteristic as the array b2,b3,,bn1b_2, b_3, \dots, b_{n-1}, where bi=1b_i = 1 if the ii-th element of the array aa is equal to both of its neighbors, and bi=0b_i = 0 if the ii-th element of the array aa is not equal to at least one of its neighbors.

For example, for the array [1,2,2,2,3,3,4,4,4,4][1, 2, 2, 2, 3, 3, 4, 4, 4, 4], the equality characteristic will be [0,1,0,0,0,0,1,1][0, 1, 0, 0, 0, 0, 1, 1].

You are given the array b2,b3,,bn1b_2, b_3, \dots, b_{n-1}. Your task is to determine whether there exists such an array aa for which the given array is the equality characteristic.

Input

The first line contains one integer tt (1t10001 \le t \le 1000) — the number of test cases.

Each test case consists of two lines:

  • the first line contains one integer nn (3n1003 \le n \le 100);
  • the second line contains n2n-2 integers b2,b3,,bn1b_2, b_3, \dots, b_{n-1} (0bi10 \le b_i \le 1).

Output

For each test case, output YES if the array aa exists, or NO if such an array does not exist. Each letter can be printed in any case.

Note

In the first example, the array a=[1,2,2,2,3,3,4,4,4,4]a = [1, 2, 2, 2, 3, 3, 4, 4, 4, 4] is suitable.

In the second example, the array a=[7,7,7]a = [7, 7, 7] is suitable.

Samples

3
10
0 1 0 0 0 0 1 1
3
1
10
0 1 0 1 1 0 0 1
YES
YES
NO

在线编程 IDE

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