Prof. Elephant has a sequence a_1,a_2,…,a_n. He has used the sequence to generate an undirected graph G with n vertices labeled by 1,2,…,n.
For each even-length contiguous subsequence a_l,a_l+1,…,a_l+2k−1, if a_l+i−1=a_l+k+i−1 always holds for i=1,2,…,k, Prof. Elephant would add k edges to G, where the endpoints of the i-th edge are vertices labeled by (l+i−1) and (l+k+i−1), and its weight is w_k.
Prof. Elephant would like to know the total weight of the minimum spanning forest of G.
There are multiple test cases. The first line of the input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an integer n (2≤n≤3×105).
The second line contains n integers a_1,a_2,…,a_n (1≤a_i≤n).
The third line contains ⌊2n⌋ integers w_1,w_2,…,w_⌊2n⌋ (1≤w_i≤109).
It is guaranteed that the sum of n in all test cases will not exceed 3×105.
For each test case, output an integer denoting the total weight of the minimum spanning forest of G.