A millennium from now, Earth, designated as Planet 1, stands on the brink of resource…
- User
A millennium from now, Earth, designated as Planet 1, stands on the brink of resource exhaustion. To ensure the survival of the human race, humanity has advanced not only in scientific knowledge but has also expanded its reach to various planets across distant galaxies. So far, p planets have been identified as suitable for human habitation. Other than Earth there exists only one, the pth planet, that can act as humanity's final sanctuary.
These planets are connected by a network of w wormholes that enable instantaneous travel between them, but the wormholes are one-way, allowing travel from one planet to another without the possibility of reverse travel. The challenge lies in safely guiding the last remaining population from Earth to the Sanctuary Planet using the limited wormhole connections available.
As the mission commander, you must navigate your spaceship each day from Earth to the Sanctuary, but each wormhole is highly unstable and can only be used once before it collapses into a singularity.
To prepare for the worst-case scenario, you need to calculate the maximum number of days you can successfully lead the humanity's last population to safety. Each day, you must find a unique path through the wormholes, ensuring that no wormhole is used more than once throughout the entire mission.
Input
The first line contains an one integer t , indicating the number of testcases. Each testcase is as follows:
The first line contains two space separated integers p and w ; where p is the number of planets, marked from 1 to p and w is the number of wormholes.
The next w lines, each contain two space separated integers pi and pj , indicating a wormhole between the planets pi and pj .
Constraints
1≤t≤20
2≤p≤500
1≤w≤1000
1≤pi,pj≤p
Output For each testcase, print one integer, the maximum number of days required to successfully guide the population to safety.
Example Input:
1 4 5 1 2 1 3 2 3 2 4 3 4
Output 2
- Assistant