Problem G

Statement
Copy Copied
Description:
Yasya was walking in the forest and accidentally found a tree with $$$n$$$ vertices. A tree is a connected undirected graph with no cycles.

Next to the tree, the girl found an ancient manuscript with $$$m$$$ queries written on it. The queries can be of two types.

The first type of query is described by the integer $$$y$$$. The weight of each edge in the tree is replaced by the bitwise exclusive OR of the weight of that edge and the integer $$$y$$$.

The second type is described by the vertex $$$v$$$ and the integer $$$x$$$. Yasya chooses a vertex $$$u$$$ ($$$1 \le u \le n$$$, $$$u \neq v$$$) and mentally draws a bidirectional edge of weight $$$x$$$ from $$$v$$$ to $$$u$$$ in the tree.

Then Yasya finds a simple cycle in the resulting graph and calculates the bitwise exclusive OR of all the edges in it. She wants to choose a vertex $$$u$$$ such that the calculated value is maximum. This calculated value will be the answer to the query. It can be shown that such a cycle exists and is unique under the given constraints (independent of the choice of $$$u$$$). If an edge between $$$v$$$ and $$$u$$$ already existed, a simple cycle is the path $$$v \to u \to v$$$.

Note that the second type of query is performed mentally, meaning the tree does not change in any way after it.

Help Yasya answer all the queries.

Input Format:
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The descriptions of the test cases follow.

The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 2 \cdot 10^5$$$) — the number of vertices in the tree and the number of queries.

The next $$$n - 1$$$ lines of each test case contain three integers $$$v$$$, $$$u$$$, $$$w$$$ ($$$1 \le v, u \le n$$$, $$$1 \le w \le 10^9$$$) — the ends of some edge in the tree and its weight.

It is guaranteed that the given set of edges forms a tree.

The next $$$m$$$ lines of each test case describe the queries:

- ^ $$$y$$$ ($$$1 \le y \le 10^9$$$) — parameter of the first type query;
- ? $$$v$$$ $$$x$$$ ($$$1 \le v \le n$$$, $$$1 \le x \le 10^9$$$) — parameters of the second type query.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. The same is guaranteed for $$$m$$$.

Output Format:
For each test case, output the answers to the queries of the second type.

Note:
None