Salaj

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Given two integers VV and EE, we say that an array AA of length EE is a valid connectivity history array (CHA, for short) if there exists a directed graph with VV vertices and EE edges and a permutation PP of length EE such that, if we were to start with an empty graph on VV vertices and add edges in the order given by permutation PP, then it is true for all 1iE1 \le i \le E that A\[i]A\[i] is the number of strongly connected components in the graph after adding the P\[i]P\[i]-th edge.

For example, for V=3V = 3 and E=3E = 3:

A=\[3,3,3]A = \[3, 3, 3] is a valid CHA because there exists the graph (1,2),(1,3),(2,3)\\{(1, 2), (1, 3), (2, 3)\\}. Regardless of the edge order chosen, the graph will always have three strongly connected components.

A=\[3,3,1]A = \[3, 3, 1] is a valid CHA because there exists the graph (1,2),(2,3),(3,1)\\{(1, 2), (2, 3), (3, 1)\\}. If we add the edges in exactly this order, the graph will have three strongly connected components after the first two edges, and a single strongly connected component after the third edge is added.

A=\[3,2,1]A = \[3, 2, 1] is not a valid CHA because there does not exist a graph with three edges on three vertices and an order of adding edges such that the number of strongly connected components decreases after each added edge.

Note that the graph is not allowed to contain self-loops or multiple edges (but if the edge (x,y)(x, y) exists, the edge (y,x)(y, x) may also exist).

You are given QQ queries, each consisting of a pair of integers (V,MAX)(V, \mathit{MAX}). Your task is to count the number of valid CHAs for each pair (V,E)(V, E) such that 1EMAX1 \le E \le \mathit{MAX}.

입력

The first line contains a single integer QQ, the number of queries (Q10Q \le 10). In the next QQ lines, the ii-th line describes the ii-th query and contains three integers V_iV\_i, MAX_i\mathit{MAX}\_i and MOD_i\mathit{MOD}\_i (1V_i501 \le V\_i \le 50, 1MAX_iV(V1)1 \le \mathit{MAX}\_i \le V \cdot (V - 1), 1MOD_i1091 \le \mathit{MOD\_i} \le 10^9).

출력

Output QQ lines, one line per query. The ii-th line must contain MAX_i\mathit{MAX}\_i integers denoting the answers for the ii-th query, taken modulo MOD_i\mathit{MOD}\_i. The jj-th integer on the ii-th line must denote the number of valid CHAs for the pair (V_i,j)(V\_i, j).