E. Tree Vertex Ordering
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, numbered $$$1, 2, \ldots, n$$$. For two vertices $$$x$$$ and $$$y$$$, let $$$d(x, y)$$$ denote the number of edges on the unique simple path between $$$x$$$ and $$$y$$$ in the tree.

For distinct nodes $$$a$$$ and $$$b$$$, we say that node $$$a$$$ dominates node $$$b$$$ if the number of vertices $$$x$$$ such that $$$d(a, x) \lt d(b, x)$$$ is strictly more than the number of vertices $$$y$$$ such that $$$d(a, y) \gt d(b, y)$$$.

You want to order the $$$n$$$ vertices such that for any $$$a, b$$$, if $$$a$$$ dominates $$$b$$$, then $$$a$$$ appears before $$$b$$$ in the order. Find such an ordering, or claim that it doesn't exist.

Input

The first line contains a single integer $$$t(1 \le t \le 3 \cdot 10^5)$$$, the number of test cases. Then the testcases follow:

  • The first line of each testcase contains a single integer $$$n (1 \le n \le 3 \cdot 10^5)$$$ — the number of vertices.
  • Each of the next $$$n - 1$$$ lines contains two integers $$$u$$$ and $$$v$$$, denoting an edge between vertices $$$u$$$ and $$$v$$$.

The sum of $$$n$$$ over all testcases does not exceed $$$3 \cdot 10^5$$$.

Output

For each test case:

  • On the first line, print YES if a valid ordering exists, and NO otherwise.
  • If a valid ordering exists, print one such ordering on a new line. If there are multiple valid orderings, you can output any of them.
Example
Input
2
6
1 2
2 3
2 4
3 5
3 6
2
1 2
Output
YES
2 3 1 4 5 6 
YES
1 2 
Note

In the first testcase, the ordered domination pairs are the following:

  • 2 dominates 1, 4, 5, 6
  • 3 dominates 1, 4, 5, 6
Note that no vertex appears after a vertex that it dominates, in the ordering $$$2, 3, 1, 4, 5, 6$$$, hence the output is valid.

The ordering $$$3, 2, 4, 5, 1, 6$$$ is also valid, among others.