#P1528C. Trees of Tranquillity
Trees of Tranquillity
Description
Soroush and Keshi each have a labeled and rooted tree on vertices. Both of their trees are rooted from vertex .
Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces round. To celebrate this fortunate event, they decided to make a memorial graph on vertices.
They add an edge between vertices and in the memorial graph if both of the following conditions hold:
- One of or is the ancestor of the other in Soroush's tree.
- Neither of or is the ancestor of the other in Keshi's tree.
Here vertex is considered ancestor of vertex , if lies on the path from (the root) to the .
Popping out of nowhere, Mashtali tried to find the maximum clique in the memorial graph for no reason. He failed because the graph was too big.
Help Mashtali by finding the size of the maximum clique in the memorial graph.
As a reminder, clique is a subset of vertices of the graph, each two of which are connected by an edge.
The first line contains an integer — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer .
The second line of each test case contains integers , being the parent of the vertex in Soroush's tree.
The third line of each test case contains integers , being the parent of the vertex in Keshi's tree.
It is guaranteed that the given graphs are trees.
It is guaranteed that the sum of over all test cases doesn't exceed .
For each test case print a single integer — the size of the maximum clique in the memorial graph.
Input
The first line contains an integer — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer .
The second line of each test case contains integers , being the parent of the vertex in Soroush's tree.
The third line of each test case contains integers , being the parent of the vertex in Keshi's tree.
It is guaranteed that the given graphs are trees.
It is guaranteed that the sum of over all test cases doesn't exceed .
Output
For each test case print a single integer — the size of the maximum clique in the memorial graph.
Note
In the first and third test cases, you can pick any vertex.
In the second test case, one of the maximum cliques is .
In the fourth test case, one of the maximum cliques is .