Rikka with Linker

n개의 라이브러리 사이 의존 관계 그래프가 주어질 때, 모든 간선 (a,b)마다 a가 b보다 앞서 나오도록 라이브러리 이름을 나열할 때 최소 길이를 구한다.

어려움8동적 계획법비트 연산그래프그리디아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

If you have ever compiled C++ projects using the command line, you are familiar with the linker. If you want to use two static libraries liba.a and libb.a while liba.a relies on libb.a, you need to put liba.a before libb.a in your command, for example, "g++ -o my my.cpp liba.a libb.a".

What if both liba.a and libb.a rely on each other? You need to add their names to the command several times, as in "g++ -o my my.cpp liba.a libb.a liba.a". Formally, if you want to use two libraries liba.a and libb.a while liba.a relies on libb.a, there must be at least one liba.a in your command which occurs before one of the occurrences of libb.a.

Now, Rikka is working on her C++ project, and there are nn static libraries she will use. There are mm pairs of dependency relationships. A pair (i,j)(i, j) means that the ii-th library relies on the jj-th library.

You know, a complicated command will never bring happiness. So Rikka wants to simplify the compile command. Specifically, Rikka wants to make the number of the names of static libraries in her compile command as small as possible. Help her find this number.

입력

The first line contains a single integer tt (1t1031 \leq t \leq 10^3), the number of test cases.

The first line of each test case contains two integers nn and mm (1n181 \leq n \leq 18, 0mn(n1)0 \leq m \leq n \cdot (n-1)).

Then mm lines follow, each line contains two integers aa and bb (1a,bn1 \leq a, b \leq n, aba \neq b) and describes a dependency relationship: library aa relies on library bb.

It is guaranteed that each dependency relationship will occur at most once, and there are at most 2020 test cases with n>12n > 12.

출력

For each test case, output a single line with a single integer: the minimum possible number of library names in Rikka's compile command.