{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"PLAIN","content":"there are N ACMers in QDU team.\nTraining 2021 is coming, and ZDP wants to select some excellent ACMers to attend the contest. There have been M matches since the last few days(No two ACMers will meet each other at two matches, means between two ACMers there will be at most one match). ZDP also asks\"Who is the winner between A and B?\" But sometimes you can\u0027t answer ZDP\u0027s 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 ZDP asks \"Who is the winner between A and B\", of course you can answer \"A\", but if ZDP ask \"Who is the winner between A and C\", you can\u0027t tell him the answer.\nAs ZDP\u0027s assistant, you want to know how many queries at most you can\u0027t tell ZDP(ask A B, and ask B A is the same; and ZDP won\u0027t ask the same question twice)."}},{"title":"Input","value":{"format":"PLAIN","content":"The input contains multiple test cases.\nThe first line has one integer,represent the number of test cases.\nEach case first contains two integers N and M(N , M \u003c\u003d 500), N is the number of ACMers in QDU team, and M is the number of matchs 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."}},{"title":"Output","value":{"format":"PLAIN","content":"For each test case, output a integer which represent the max possible number of queries that you can\u0027t tell ZDP."}},{"title":"Sample Input","value":{"format":"PLAIN","content":"3\n3 3\n1 2\n1 3\n2 3\n3 2\n1 2\n2 3\n4 2\n1 2\n3 4"}},{"title":"Sample Output","value":{"format":"PLAIN","content":"0\n0\n4\n"}},{"title":"Explanation","value":{"format":"PLAIN","content":"In the case3, if ZDP ask (1 3 or 3 1) (1 4 or 4 1) (2 3 or 3 2) (2 4 or 4 2), then you can\u0027t tell him who is the winner."}}]}