You may have seen some similar problems before, but please, notice the difference in path values. You are given a tree with

nodes labelled from

to

, the root of which is the node labelled

. Every node in the tree will be endowed with values related to given parameters

, and each edge in the tree is endowed with a given bitwise operator which is one of the bitwise OR '|', the bitwise AND '&' and the bitwise XOR '^'
For any pair of nodes
_%7B%7D)
indicating the

-th and the

-th node in the tree, the shortest path connecting them in the tree, denoted by
together with operators along the path provide a value associated with
_%7B%7D)
given by
where

is the operator on the edge between the node

and the node

in this path.
Now you are given

queries, each of which contains two integers

and

. For this query, the value of the

-th node will be set to be
)
, and you are asked to calculate the bitwise OR, AND and XOR sum respectively of values for all the pairs
_%7B%7D)
where the

-th node is an ancestor of the

-th node. Note that a node is not considered as an ancestor of itself.