E. Tree XOR
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a tree with $$$n$$$ vertices, labeled from $$$1$$$ to $$$n$$$. Each vertex $$$i$$$ has a hidden label $$$v_i$$$, and the array of hidden values $$$[v_1, v_2, \ldots, v_n]$$$ forms a permutation of integers from $$$1$$$ to $$$n$$$.

You are not given the hidden values directly. Instead, you are given the structure of the tree and the weights of its $$$n - 1$$$ edges. The weight of the edge connecting vertex $$$i$$$ and vertex $$$j$$$ is $$$v_i \oplus v_j$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.

Your task is to reconstruct the hidden labels $$$v_1, v_2, \dots v_n$$$ with the given information.

Input

The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 100)$$$, representing the number of test cases.

The first line of each test case contains $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^5)$$$, the number of vertices in the tree.

The next $$$n - 1$$$ lines of each test case each contain three integers $$$i$$$, $$$j$$$, and $$$v_i \oplus v_j$$$ and each represent an edge in the tree.

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

Output

On a single line, output the labels of vertices $$$1, 2, 3, \ldots, n$$$ in order.

If there are multiple solutions, you can output any of them.

Scoring
SubtaskConstraintPoints
$$$1$$$$$$n$$$ is odd$$$30$$$
$$$2$$$$$$\sum n \leq 5000$$$$$$30$$$
$$$3$$$No additional constraints$$$90$$$
Example
Input
1
5
1 2 7
1 3 5
3 4 4
3 5 3
Output
4 3 1 5 2 
Note

The labels satisfy the constraints because we have

  • $$$v_1 \oplus v_2 = 4 \oplus 3 = 7$$$
  • $$$v_1 \oplus v_3 = 4 \oplus 1 = 5$$$
  • $$$v_3 \oplus v_4 = 1 \oplus 5 = 4$$$
  • $$$v_3 \oplus v_5 = 1 \oplus 2 = 3$$$