CF2109A.It's Time To Duel

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

It's Time To Duel

Something you may not know about Mouf is that he is a big fan of the Yu-Gi-Oh! card game. He loves to duel with anyone he meets. To gather all fans who love to play as well, he decided to organize a big Yu-Gi-Oh! tournament and invited nn players.

Mouf arranged the nn players in a line, numbered from 11 to nn. They then held n1n - 1 consecutive duels: for each ii from 11 to n1n - 1, player ii faced player i+1i + 1, producing one winner and one loser per match. Afterward, each player reports a value ai(0ai1)a_i(0 \le a_i \le 1):

  • 00 indicating they won no duels;
  • 11 indicating they won at least one duel.

Since some may lie about their results (e.g., reporting a 11 instead of a 00, or vice versa) to influence prize outcomes, Mouf will cancel the tournament if he can prove any report to be false.

Given the array aa, determine whether at least one player must be lying.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains one integer nn (2n1002 \le n \le 100) — the number of players in the tournament.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai10 \le a_i \le 1) — denoting the report of the ii-th player.

Output

For each test case, print "YES" (without quotes) if there is at least one liar among the players, and "NO" (without quotes) otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Note

In the first test case, it is consistent if player 22 defeats both players 11 and 33, so nobody's report is necessarily false.

In the second test case, in the only match between players 11 and 22, one must win — but both claimed zero wins, so someone must be lying.

In the third test case, the tournament consists of exactly one duel between players 11 and 22 — but it's impossible for both to win, concluding that at least one report is false.

In the fourth test case, a possible scenario is that player 22 won against player 11, then 33 won against 22, and then 44 won against 33. All reports align, so there is no evidence that someone lied.

Samples

6
3
0 1 0
2
0 0
2
1 1
4
0 1 1 1
4
1 0 0 1
7
0 1 0 1 0 1 0
NO
YES
YES
NO
YES
NO

在线编程 IDE

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