The first line contains two integers n,mn, mn,m (2≤n,m≤5002\leq n, m\leq 5002≤n,m≤500) — the number of vertices in T1T_1T1 and T2T_2T2, respectively.
The second line contains nnn integers c1,1,c1,2,…,c1,nc_{1, 1}, c_{1, 2}, \dots, c_{1, n}c1,1,c1,2,…,c1,n (1≤c1,i≤5001 \le c_{1, i} \le 5001≤c1,i≤500) — the value of each vertex in T1T_1T1.
The third line contains mmm integers c2,1,c2,2,…,c2,mc_{2, 1}, c_{2, 2}, \dots, c_{2, m}c2,1,c2,2,…,c2,m (1≤c2,i≤5001 \le c_{2, i} \le 5001≤c2,i≤500) — the value of each vertex in T2T_2T2.
Each of the next n−1n-1n−1 lines contains two integers uuu and vvv (1≤u,v≤n1 \le u, v \le n1≤u,v≤n) — an edge connecting vertices uuu and vvv in T1T_1T1.
Each of the next m−1m-1m−1 lines contains two integers uuu and vvv (1≤u,v≤m1 \le u, v \le m1≤u,v≤m) — an edge connecting vertices uuu and vvv in T2T_2T2.