spoj#EN. Entrapment
Entrapment
The separatist leader General Grievous, the second in command of Count Dooku, comes to know that Chancellor Palpatine’s convoy, escorted by Obi-wan and Anakin, is scheduled to depart from Kashyyyk in the Middle Rim of the Universe to Alderaan. General Grievous is aware that there are multiple paths going via different sets of planets from Kashyyyk to Alderaan. To make his abduction attempt successful, he decides to send his robots to the planet closest to Kashyyyk, other than itself, which lies on all the possible paths from Kashyyyk to Alderaan. Since you have pledged your allegiance to Count Dooku, you need to help him identify this planet.
The planetary map which is given to you for this purpose consists of a set of one-way connections between planets. You also know that a pair of planets can have at most one connection between them in each direction and there is always a path from Kashyyyk to Alderaan.
Note: In the given example, the planet with index 5 is the required planet.
Input Description
The first line of the input is a positive integer t ≤ 20, which is the number of test cases. The descriptions of the test cases follow one after the other. The first line of each test case is a pair of positive integers n, m (separated by a single space). 2 ≤ n ≤ 30011 is the number of planets and m ≤ 100011 is the number of connections between planets. The planets are indexed with integers from 1 to n and the indices of Kashyyyk and Alderaan are 1, n respectively. Each of the next m lines contains two integers p,q, meaning that there is a one-way connection from planet p to planet q.
Output Description
The output should contain t lines. The ith line corresponds to the ith test case. The output for the ith test case should be the index of the planet with the required property.
Example
Input
2
3 2
1 3
3 2
4 4
1 3
3 4
1 2
2 4
Output
3
4