Swapnil is resident of ancient city Codenagri. His best friend Sumedh is a City Engineer who is planning to reconstruct the city with all advanced amenities. He has recieved blue-print of whole city map from his team. He observes that buildings in city are connected to each other with unidirectional paths. He's not happy seeing that there are paths which can lead to same building again. Swapnil is so absent-minded that he can't even remember which building he visited earlier. If the city is having path that can lead to same building again it is possible that Swapnil could visit the same building infinite times without even knowing and so Swapnil can get lost! To make travelling easy in city for his friend, Sumedh decides to change the city-plan. He decides to combine buildings to construct Mega building/s in such a way that there is no chance of Swapnil getting lost.
To do this you must follow a rule:
You can combine two or more buildings/mega buildings in a Mega building that will maintain all the paths of its member buildings.
Reassembling city, Sumedh is happy because his friend is happy and also he got a chance to show his skills in building marvelous Mega buildings.
Note: The buildings are numbered from 0 to N-1.
Input format:
First line will denote T, number of testcases.
In each testcase first line will contain N , M denoting number of buildings in city and paths connecting them respectively.
next M lines will contain two integers a , b showing directed paths between the buldings directed from a to b.
Output format:
Print the total number of Mega buildings in reassembled city.
Constraints:
2 <= N <= 100000
1 <= M <= (N * (N-1))
1 <= T <= 3
This is the initial arrangement.
Here buildings 1 and 2 can be combined into a single mega building.
Further this one mega building and buildings 0 and 3 can be combined into a single mega building.
Thus finally we have one mega building here.