E. Game on a Graph
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Ana and Baq are playing a game. The game consists of the following: initially, there is a graph $$$G$$$ that is not necessarily connected, with its $$$n$$$ vertices numbered from $$$0$$$ to $$$n-1$$$. One of the vertices is marked as the *winning vertex*. The players take turns (starting with Ana), and on each turn, the player selects a connected component of the graph and removes the vertex with the smallest number from the component (also removing all edges incident to it). The first player to remove the winning vertex wins.

Given the graph $$$G$$$, Ana wonders which vertices she can win with (even if Baq plays optimally) if they are marked as winners.

Input

The input begins with the number of cases $$$T$$$. This is followed by $$$T$$$ cases, each describing the graph $$$G$$$ with a line containing the integers $$$n$$$, $$$m$$$, followed by $$$m$$$ lines, each with two integers $$$u, v$$$, indicating that there is an edge between vertices $$$u$$$ and $$$v$$$.

Output

For each case, write in one line the numbers of the vertices for which Ana wins, sorted in ascending order.

Scoring

$$$1 \leq T \leq 100$$$, $$$1 \leq n \leq 10^5$$$, $$$1 \leq m \leq 10^5$$$. The sum of $$$n+m$$$ for all cases is less than $$$2 \cdot 10^6$$$.

9 points: $$$n \leq 10, m \leq 20$$$, sum of $$$n+m$$$ for all cases less than $$$700$$$.

28 points: $$$n \leq 1000, m \leq 1000$$$, sum of $$$n+m$$$ for all cases less than $$$25000$$$.

8 points: $$$G$$$ is a tree (connected graph without cycles) that has the property that a path from node $$$0$$$ to any other node visits nodes in ascending order of numbers.

25 points: $$$G$$$ is a path (tree with only two vertices of degree 1).

30 points: No additional restrictions.

Example
Input
3
6 4
0 4
0 5
1 2
1 3
6 5
0 4
0 5
1 2
1 3
0 1
6 7
0 4
0 5
1 2
1 3
0 1
2 3
4 5
Output
0 1 2 3 4 5
0 2 3
0 2