#P7788. Tokitsukaze and Colorful Tree

Tokitsukaze and Colorful Tree

Tokitsukaze and Colorful Tree

Problem Description

Tokitsukaze has a rooted tree with nn nodes, whose nodes are labeled from 11 to nn and whose root is node 11. Furthermore, each node ii has its own color colicol_i and its own weight valival_i, where the color is labeled as a number between 11 and nn, representing one of nn given colors. Here are two types of operation: ● 11 xx vv -- set valxval_x as vv. ● 22 xx cc -- set colxcol_x as cc. Tokitsukaze wants to execute qq opeations and for i=1,2,,q+1i = 1, 2, \ldots, q + 1, after finishing the first (i1)(i - 1) operations, she wants to know the value of $$\sum_{\substack{1 \leq u < v \leq n \ col_u = col_v \ \text{node }u\text{ is not an ancestor of node }v \ \text{node }v\text{ is not an ancestor of node }u}}{(val_u \oplus val_v)}$$ where \oplus is the bitwise exclusive OR operation. If you are not familiar with the bitwise exclusive OR, you may refer to http://en.wikipedia.org/wiki/Bitwise_operation#XOR and http://baike.baidu.com/item/xor/64178 .

Input

There are several test cases. The first line contains an integer TT (1T81 \leq T \leq 8), denoting the number of test cases. Then follow all the test cases. For each test case, the first line contains an integer nn (1n105)(1 \leq n \leq 10^5), denoting the number of nodes. The second line contains nn integers, where the ii-th intger is colicol_i (1colin)(1 \leq col_i \leq n), denoting the color of node ii at the beginning. The third line contains nn integers, where the ii-th intger is valival_i (0vali<220)(0 \leq val_i < 2^{20}), denoting the weight of node ii at the beginning. The next (n1)(n - 1) lines describe the tree, where each line contains two integers uu and vv (1u,vn)(1 \leq u, v \leq n), representing an edge connecting node uu and node vv. The next line contains an integer qq (0q105)(0 \leq q \leq 10^5), denoting the number of operations. The next qq lines describe these operations in chronological order of occurrence, where each line contains three integers such that ● if the first integer is 11, then the following two integers are xx and vv (1xn,0v<220)(1 \leq x \leq n, 0 \leq v < 2^{20}), representing an operation of the first type, or ● otherwise the first integer is 22, and the following two integers are xx and cc (1x,cn)(1 \leq x, c \leq n), representing an operation of the second type. It is guaranteed that the size of the standard input file does not exceed 3232 MiB, so you may need to use a fast approach to read the input data.

Output

For each test case, output (q+1)(q + 1) lines, where the ii-th line contains an integer, denoting the value Tokitsukaze wants to know after the first (i1)(i - 1) operations.

Sample Input

1
5
1 1 1 1 1
1 2 4 8 16
1 2
3 1
2 4
2 5
2
1 3 32
2 3 2

Sample Output

62
146
24

Hint

For the only sample case: ● before the first operation, the value is (2 ⊕ 4) + (4 ⊕ 8) + (4 ⊕ 16) + (8 ⊕ 16) = 6 + 12 + 20 + 24 = 62; ● before the second operation, the value is (2 ⊕ 32) + (32 ⊕ 8) + (32 ⊕ 16) + (8 ⊕ 16) = 34 + 40 + 48 + 24 = 146; ● after all the operations, the value is 8 ⊕ 16 = 24.

Source

2020 Multi-University Training Contest 3