/*
As long as the vertex's inbound or outbound degree is greater than n/2, it can be determined that it does not match the intermediate point,
That is, if the answer is incremented, And the inbound or outbound degree is obtained, you can use the passing closure Floyd of the directed graph.AlgorithmHere,
The time complexity is O (n ^ 3)
*/
# Include <iostream>
# Include <cstring>
# Include <cstdio>
Using namespace STD;
# Define x 100
Int map [x] [X], n, m;
Void Floyd ()
{
For (int K = 1; k <= N; k ++) // evaluate the transfer closure using the Floyd algorithm
For (INT I = 1; I <= N; I ++)
For (Int J = 1; j <= N; j ++)
Map [I] [J] = map [I] [J] | (Map [I] [k] & map [k] [J]);
}
Int main ()
{
Freopen ("sum. In", "r", stdin );
Freopen ("sum. Out", "W", stdout );
Int t, x, y;
Cin> T;
While (t --)
{
Memset (MAP, 0, sizeof (MAP ));
Scanf ("% d", & N, & M );
For (INT I = 0; I <m; I ++)
{
Scanf ("% d", & X, & Y );
Map [x] [Y] = 1; // indicates that X from the vertex to Y is in the directed edge.
}
Floyd ();
Int ans = 0;
For (INT I = 1; I <= N; I ++)
{
Int sum1 = 0;
Int sum2 = 0;
For (Int J = 1; j <= N; j ++) // calculates the vertex's inbound or outbound degrees.
{
If (I = J)
Continue;
If (Map [I] [J]) // if it is an outbound degree
Sum1 ++;
If (Map [J] [I]) // It is the inbound degree.
Sum2 ++;
If (sum1> n/2 | sum2> n/2)
{
Ans ++;
Break;
}
}
}
Cout <ans <Endl;
}
Return 0;
}