
126  The 10th Zhejiang Provincial Collegiate Programming Contest  K
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. InputThere 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 n1 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 n1 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. OutputFor each test case, print the minimal cost of candies to help Sheldon become the ONLY leader. Sample Input2 4 1 1 2 1 10 100 3 3 2 1 10 Sample Output0 11 HintIn the first case,
