시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 512 MB222100.000%

문제

Eryk with his partner called "Synek" are planning next spoof. Usually they swindle foreingers by offering false banknotes on low exchange rate, so they have to drive a lot around country to avoid recognition.

But to do this, they need to find a city where they can build a base. Cities and roads in their homeland can be viewed as a directed graph with $n$ vertices numbered with integers from $1$ to $n$ and specific property -- there is a directed edge from vertex $i$ to vertex $i + 1$ for each valid $i$.

Since they want to get back to base after each "trip" so they finds cycles really attractive. They decided to build a base in a city which lies on all cycles in their country. Because there can be multiple such cities, they asked you to write down all of them. If there is no cycle in the graph, they can build a base in any city.

Formally a cycle is a path starting and ending in the same city and visiting at least one other city (possibly multiple times).

입력

In the first line one integer $Z \le 50$ is given, denoting number of testcases described in following lines. 

The first line of the test case contains two integers $n$ and $m$, denoting the number of cities and roads. Each of the following $m$ lines two integers $a_i, b_i$ ($a_i \neq b_i$), denoting that there is a directed road from $a_i$ to $b_i$. There can exist more than one road from $a_i$ to $b_i$.

출력

For each test case your program should write the number of cities where Eryk and "Synek" can build base, followed by indices of those cities in ascending order.

제한

  • $n \in [1, 500\,000], m \in [0, 500\,000]$
  • sum of $n$ and sum of $m$ over all testcases does not exceed $1\,000\,000$.

예제 입력 1

2
4 4
1 2
2 3
3 4
4 2
4 5
1 2
2 3
3 4
2 1
4 3

예제 출력 1

3 2 3 4
0