#P1585G. Poachers

    ID: 6125 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>dpgamesgraphstrees*2500

Poachers

No submission language available for this problem.

Description

Alice and Bob are two poachers who cut trees in a forest.

A forest is a set of zero or more trees. A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a node vv is the next vertex on the shortest path from vv to the root. Children of vertex vv are all nodes for which vv is the parent. A vertex is a leaf if it has no children.

In this problem we define the depth of vertex as number of vertices on the simple path from this vertex to the root. The rank of a tree is the minimum depth among its leaves.

Initially there is a forest of rooted trees. Alice and Bob play a game on this forest. They play alternating turns with Alice going first. At the beginning of their turn, the player chooses a tree from the forest. Then the player chooses a positive cutting depth, which should not exceed the rank of the chosen tree. Then the player removes all vertices of that tree whose depth is less that or equal to the cutting depth. All other vertices of the tree form a set of rooted trees with root being the vertex with the smallest depth before the cut. All these trees are included in the game forest and the game continues.

A player loses if the forest is empty at the beginning of his move.

You are to determine whether Alice wins the game if both players play optimally.

Each test contains multiple test cases. The first line contains the number of test cases tt (1t51051 \leq t \leq 5 \cdot 10^5). Description of the test cases follows.

The first line of each test case contains a single integer nn (1n51051 \leq n \leq 5 \cdot 10^5) — total number of vertices in the initial forest.

The second line contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n (0pin0 \leq p_i \leq n) — description of the forest. If pi=0p_i = 0, then the ii-th vertex is the root of a tree, otherwise pip_i is the parent of the vertex ii. It's guaranteed that pp defines a correct forest of rooted trees.

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

For each test case, print "YES" (without quotes) if Alice wins, otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower).

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t51051 \leq t \leq 5 \cdot 10^5). Description of the test cases follows.

The first line of each test case contains a single integer nn (1n51051 \leq n \leq 5 \cdot 10^5) — total number of vertices in the initial forest.

The second line contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n (0pin0 \leq p_i \leq n) — description of the forest. If pi=0p_i = 0, then the ii-th vertex is the root of a tree, otherwise pip_i is the parent of the vertex ii. It's guaranteed that pp defines a correct forest of rooted trees.

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

Output

For each test case, print "YES" (without quotes) if Alice wins, otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower).

Samples

Sample Input 1

4
4
0 1 0 3
7
0 1 2 0 4 5 6
4
0 1 1 2
7
0 1 1 2 2 3 3

Sample Output 1

NO
YES
NO
YES

Note

In the first test case Bob has a symmetric strategy, so Alice cannot win.

In the second test case Alice can choose the second tree and cutting depth 11 to get a forest on which she has a symmetric strategy.

In third test case the rank of the only tree is 22 and both possible moves for Alice result in a loss. Bob either can make the forest with a symmetric strategy for himself, or clear the forest.

In the fourth test case all leafs have the same depth, so Alice can clear the forest in one move.