TORONTO KIDS COMPUTER CLUB | Aurora Saturday 14:30 Python Practice 22.04.30.
20596

# Aurora Saturday 14:30 Python Practice 22.04.30.

## 05 May Aurora Saturday 14:30 Python Practice 22.04.30.

Question: （floyd-warshall)

There are N players in Dota team.
This year’s The Weekend Battle Cup is coming, and Jack want to select some excellent player to attend the contest. There have been M matches since the last few days(No two players will meet each other at two matches, means between two players there will be at most one match). Jack also asks “Who is the winner between A and B?” But sometimes you can’t answer Jack’s query, for example, there are 3 people, named A, B, C. and 1 match was held between A and B, in the match A is the winner, then if Jack asks “Who is the winner between A and B”, of course you can answer “A”, but if Jack ask “Who is the winner between A and C”, you can’t tell him the answer.

As Jack’s assistant, you want to know how many queries at most you can’t tell Jack (ask A B, and ask B A is the same; and Jack won’t ask the same question twice).

Input
The input contains multiple test cases.
The first line has one integer, represent the number of test cases.
Each case first contains two integers N and M(N , M <= 500), N is the number of player in Dota team, and M is the number of matches have been held. The following M lines, each line means a match and it contains two integers A and B, means A wins the match between A and B. And we define that if A wins B, and B wins C, then A wins C.

Output
For each test case, output a integer which represent the max possible number of queries that you can’t tell Jack.

`Sample Input33 31 21 32 33 21 22 34 21 23 4Sample Output004`
` `