At the beginning of the semester in kindergarten, the n little kids (indexed from 1 to n, for convenience) in class need to elect their new leader.

The i^{th} kid will vote for his best friend f_{i}(where 1 ≤ f_{i}≤ n, and it's too shame to vote for yourself, so f_{i}≠ i). And the kid who gets the most votes will be the leader. If more than one kids who get the largest number of votes, there will be multiple leaders in the new semester.

Little Sheldon (the kid with index 1) is extremely vain, and he would like to be the ONLY leader. (That means the number of votes he gets should strictly larger than any other.) Soon Sheldon found that if he give c_{i}candies to the i^{th}kid, the i^{th}kid would regard Sheldon as the new best friend, and of course vote for Sheldon.

Every kid including Sheldon loves candies. As an evil programmer, please help the evil Sheldon become the ONLY leader with minimum cost of candies. By the way, Sheldon should vote for any one he wants EXCEPT himself.

Input

There are multiple test cases. The first line of input contains an integer T (T ≤ 100) indicating the number of test cases. Then T test cases follow.

The first line of each case contains one integer: n (3 ≤ n ≤ 100) -- the number of kids in class.

The second line contains n-1 integers: f_{i} (1 ≤ f_{i} ≤ n, f_{i} ≠ i, and 2 ≤ i ≤ n) -- represents that the best friend of i^{th}kid is indexed with f_{i}.

The third line contains n-1 integers: c_{i}(1 ≤ c_{i}≤ 1000, and 2 ≤ i ≤ n) -- represents that if Sheldon gave c_{i}candies to the i^{th}kid, the i^{th}kid would vote Sheldon, instead of their old best friend f_{i}, as the new semester leader.

Output

For each test case, print the minimal cost of candies to help Sheldon become the ONLY leader.

Samples

input

2
4
1 1 2
1 10 100
3
3 2
1 10

output

0
11

Hint

In the first case,

If Sheldon vote for 2^{nd}kid, the 2^{nd}kid and Sheldon will both have 2 votes. In this case, Sheldon have to pay 100 candies to the 4^{th}kid, and get 3 votes to win;

If Sheldon vote for 3^{rd}or 4^{th}kid, Sheldon will win with 2 votes without sacrifice any candy.