Under construction

Still being built. Things may change

Salaj

Time limit2sMemory limit256 MB

Summary
For each edge count j up to MAX, count the valid connectivity history arrays on V vertices with j edges, modulo MOD.
Level

Hard9 of 10

Topics
Dynamic programming, Combinatorics, Graph
Solved
No attempts yet

Statement

Given two integers VV and EE, an array AA of length EE is a valid connectivity history array (CHA) if there is a directed graph with VV vertices and EE edges and a permutation PP of length EE such that, starting from an empty graph on VV vertices and adding edges in the order given by PP, every 1≤i≤E1 \le i \le E satisfies: after the P[i]P[i]-th edge is added, the number of strongly connected components is A[i]A[i]. The graph may not contain self-loops or multiple edges, but if the edge (x,y)(x, y) exists, the edge (y,x)(y, x) may also exist. For example, with V=3V = 3 and E=3E = 3, A=[3,3,3]A = [3, 3, 3] is valid because the graph {(1,2),(1,3),(2,3)}\{(1, 2), (1, 3), (2, 3)\} always has three strongly connected components, whatever the order. A=[3,3,1]A = [3, 3, 1] is valid because the graph {(1,2),(2,3),(3,1)}\{(1, 2), (2, 3), (3, 1)\} added in that order has 3, 3, then 1 strongly connected components. A=[3,2,1]A = [3, 2, 1] is not valid, because no graph with three edges on three vertices has a edge order where the count drops after each added edge.

Input

The first line contains QQ, the number of queries (Q≤10Q \le 10). Each of the next QQ lines contains three integers ViV_i, MAXiMAX_i, and MODiMOD_i (1≤Vi≤501 \le V_i \le 50, 1≤MAXi≤Vi(Vi−1)1 \le MAX_i \le V_i(V_i - 1), 1≤MODi≤1091 \le MOD_i \le 10^9).

Output

For each query, print one line with MAXiMAX_i integers. The jj-th integer is the number of valid CHAs for the pair (Vi,j)(V_i, j), taken modulo MODiMOD_i, where 1≤j≤MAXi1 \le j \le MAX_i.

Examples1

  1. Example 1

    Input
    2
    5 10 666013
    6 9 10
    
    Expected output
    1 2 4 9 21 50 110 209 351 546
    1 2 4 9 1 1 6 0 7