#SL2310E. Equivalence

Equivalence

Equivalence

You are given two trees T1,T2T_1,T_2, both with nn vertices. The lengths of edges of T1T_1 are given. The length of each edge is non-negative.

A tree TT with nn vertices is good, if there is a way to assign each edge on T2T_2 with a length which satisfies the following condition:

  • For each pair i,ji,j satisfying 1i<jn1 \leq i < j \leq n, the distances of ii and jj on TT and T2T_2 are the same.

You can perform the following operation on T1T_1: select an edge on T1T_1 and replace its length with any non-negative integer.

Find the minimum number of operations to make T1T_1 good.

Input

The first line of input contains a single integer T(1T8600)T \: (1 \leq T \leq 8600), denoting the number of test cases.

For each test case, the first line contains one integer n(2n106)n \: (2 \leq n \leq 10^6).

The second line contains n1n − 1 integers p2,p3,,pn(1pin)p_2,p_3,\dots ,p_n (1 \leq p_i \leq n).

The third line contains n1n-1 integers $val_2, val_3, \dots,val_n \: (0 \leq val_i \leq 10^9)$

These two lines denotes n1n-1 edges (u,pu)(u, p_u) with weight valuval_u on T1T_1.

The fourth line contains n1n − 1 integers p2,p3,,pn(1pin)p′_2,p′_3,\dots ,p′_n \: (1 \leq p′_i \leq n), denoting n1n − 1 edges (u,pu)(u,p′_u) on T2T_2.

Output

For each test case, the only line contains one integer denoting the answer.

Example

1
5
1 5 2 2
0 2 3 1
5 5 5 1
1