Cycle Game

No attempts yetTime limit1sMemory limit128 MB

Problem

Two players play a game on a cycle. A cycle is given, and every edge is labelled with a non-negative integer; at least one of these integers is 00. A coin is placed on one vertex of the cycle, and the game starts from that vertex. The two players alternate turns, and on their turn the current player does the following.

  1. Choose an edge incident to the vertex holding the coin.
  2. Strictly decrease that edge's value, replacing it with any smaller non-negative integer.
  3. Move the coin along that edge to the adjacent vertex.

The game ends when a player, on their turn, cannot move because every edge incident to the vertex holding the coin equals 00. That player loses.

Figure 1 shows one play of the game. Here Alice moves first and Bob moves second. In the starting position (a) the only edge Alice can use is the right edge of the vertex holding the coin, so she lowers its value from 22 to 00 and moves the coin along it, turning (a) into (b). Bob then has only the down edge available and lowers it from 55 to 11, turning (b) into (c). In (c) Alice takes the up edge and lowers it from 11 to 00, turning (c) into (d). Finally, in (d) Bob has no move because every edge incident to his vertex is 00, so Alice wins.

(a) Alice

(b) Bob

(c) Alice

(d) Bob

Figure 1: An example of the cycle game (the coin sits on the black vertex).

Whenever the game starts from the position in Figure 1 (a), the first player can always win no matter how the second player responds; in other words, the first player has a winning strategy from that position.

Given a starting position, decide whether the first player has a winning strategy.

Input

The first line contains the number of test cases TT.

Each test case consists of two lines. The first line contains an integer NN (3N203 \le N \le 20), the number of vertices of the cycle. The second line contains the NN non-negative integers written on the edges, listed in clockwise order starting from the vertex that holds the coin and separated by single spaces. At least one of these NN integers is 00, and none of them exceeds 3030.

Output

For each test case, print exactly one line: YES if the first player has a winning strategy from the given starting position, and NO otherwise.