Byteland has a network of computers that forms a tree structure. A tree is a connected graph that has no cycles.
Each computer has a special database and special software. The database has initially a list . The list has only one element initially. The software is programmed to do a special task. When a list is given to the computer ’s special software, it starts to iterate through the list . For each element of the list , the software does the following:
After completing the iteration, the software then sorts the list in ascending order. For example, if a list is initially and we give the lists to the software of computer one by one, then eventually the list will be .
To ensure the security of the network, each computer sends a copy of all the lists in its database to its parent computer (if exists) only. When a computer gets the lists from a child computer, the computer adds the lists to its database and also gives the lists to its special software to update the list . Only after receiving all the lists from all the children's computers and updating the list accordingly, a computer sends a copy of all the lists in its database to its parent computer (if exists).
For each computer , you have to tell how many distinct lists are present in its database after completing all the above operations. Two lists are different if either they have different sizes or one list has at least one element that is not present in the other list.
Input starts with an integer , the number of test cases.
In each test case, the first line contains an integer , the number of computers.
The next line contains space-separated integers , the single initial element of the list of computer .
The last line of each test case contains space-separated integers , the parent computer of computer . If computer is the root of the tree, will be .
It is guaranteed that the computer network will form a tree structure and the sum of over all test cases will not be greater than . It is also guaranteed that if , then .
In each test case, print space-separated integers in a line. The integer represents the number of distinct lists present in the database of the computer .
2 4 7 10 15 10 3 1 -1 1 3 25 25 25 -1 1 1
2 1 3 1 1 1 1
In the first test case, the computer network looks like the below tree where the computer is the root of the tree:
The lists in computer ’s database are: where the first list is the list . The three distinct lists are: .