Hamilton Path

방향 그래프에서 모든 두 정점 사이에 연속한 위치를 잇는 간선만 존재하도록 하는 순열의 개수를 세고, 개수가 n 이하이면 그 값들을 사전순으로 출력한다.

어려움9그래프조합론구현위상 정렬아직 제출이 없습니다시간 제한4초메모리 제한512 MB

문제

You are given a directed graph with nn vertices and mm edges. The vertices are labeled from 11 to nn. You need to find all the permutations of vertices p_1,p_2,,p_np\_1, p\_2, \ldots, p\_n satisfying the following constraint:

  • For all 1i<jn1 \leq i < j \leq n, an edge (p_i,p_j)(p\_i, p\_j) exists if and only if j=i+1j = i + 1.

We define the value of a permutation p_1,p_2,,p_np\_1, p\_2, \ldots, p\_n as (_i=1np_i10ni)mod(109+7).\left(\sum\_{i = 1}^n p\_i \cdot 10^{n - i}\right) \bmod (10^9 + 7)\text{.}

Output the number of such permutations modulo 109+710^9 + 7. If the number of such permutations is not greater than nn, you also need to consider them all in lexicographical order, and output their values in this order.

입력

The first line contains an integer TT (T105T \leq 10^5) indicating the number of test cases.

For each test case, the first line contains two integers nn and mm (n1n \geq 1, m0m \geq 0, 1n51051 \leq \sum n \leq 5 \cdot 10^5, 1m1061 \leq \sum m \leq 10^6).

Each of the following mm lines contains two integers uu and vv (1u,vn1 \leq u, v \leq n, uvu \neq v) indicating that there is a directed edge from uu to vv in the graph. Note that the graph can contain parallel edges.

출력

For each test case, output the number of the permutations modulo 109+710^9 + 7 in the first line. If the number of permutations is not greater than nn, print another line with space-separated values of all the permutations, considered in lexicographical order. You \textbf{don't need to} output an empty line if the number is greater than nn or there is no solution.