You are given a tree on $$$n$$$ nodes rooted at node $$$1$$$. A spider and a fly are in the tree. The spider has three legs which are initially on nodes $$$a$$$, $$$b$$$, and $$$c$$$. The fly is on node $$$f$$$ and does not move.
Some nodes are considered to be in the shadow of the spider. A node is in the shadow of the spider if it lies on any of the three shortest paths between its legs, $$$a$$$–$$$b$$$, $$$a$$$–$$$c$$$, and $$$b$$$–$$$c$$$.
The spider can move its legs from vertices $$$a$$$, $$$b$$$, $$$c$$$ to vertices $$$a'$$$, $$$b'$$$, $$$c'$$$ if the size of its shadow remains constant and $$$\max\{\textrm{dist}(a, a'), \textrm{dist}(b, b'), \textrm{dist}(c, c')\}\leq 1$$$. The function $$$\textrm{dist}(u,\,v)$$$ indicates the number of edges on the shortest path between nodes $$$u$$$ and $$$v$$$ in the tree.
For example, here is one possible sequence of two moves by a spider with $$$6$$$ nodes in its shadow. The vertices that have a red outline are in the shadow of the spider, and the vertices that are colored red are the spider's legs.
The spider eats through its legs. Determine whether the spider can move any of its legs to the fly's location, after any number of moves (possibly zero).
The first line of the input contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$) — the number of vertices in the tree.
The next line of each test case contains $$$n-1$$$ integers $$$p_2,\,p_3,\,\ldots,\,p_n$$$ ($$$1 \le p_i \lt i$$$) — the parents of each vertex in the tree, except the root.
The next line of each test case contains three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1\leq a,\,b,\,c\leq n$$$) — the initial positions of each of the spider's legs.
The fourth and final line of each test case contains an integer $$$f$$$ ($$$1\leq f\leq n$$$) — the position of the fly.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print "YES" if the spider is able to catch the fly, and "NO" 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.
7212 2 2161 1 3 1 52 4 5161 1 3 1 52 4 61181 2 3 2 5 3 1 7 7 7 4 2 12 4 12 4 1512 15 1216121 1 3 4 5 5 7 4 9 10 91 6 1112121 1 3 4 5 5 7 4 9 10 91 6 114121 1 3 4 5 5 7 4 9 10 91 6 116
Yes Yes No Yes Yes No Yes
In the first test case, all legs of the spider are initially on vertex $$$2$$$, so that is the only vertex in the shadow. By moving all legs to vertex $$$1$$$ at the same time, the spider can reach the food while keeping its shadow the same size.
In the second test case, the spider can use this move to reach the food with one of its legs:
In the third test case, the food is located at vertex $$$1$$$, which is in the shadow of the spider, but the spider cannot move any of its legs to the food: