Matrix nightmare

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

문제

As Obi-Wan would put it: “This isn’t the problem statement you are looking for. Move along.”

The double factorial numbers are the numbers d_id\_i defined by the following recursive formula: d_0=1d\_0 = 1, and i>0∀i > 0 : d_i=d_i1i!d\_i = d\_{i-1} \cdot i!. For example, d_3=1!2!3!=12d\_3 = 1! \cdot 2! \cdot 3! = 12.

Sequences of length nn with all elements belonging into the set 0,,n1\\{0, \dots ,n-1\\} are called limited sequences of order nn. For example, (0,2,0,1)(0, 2, 0, 1) is a limited sequence of order 44. The set of all limited sequences of order nn will be denoted S_nS\_n.

The spread factor of a sequence A=(a_0,,a_n1)A = (a\_0, \dots , a\_{n-1}) is the value σ(A)=_i=0n1_j=i+1n1(a_ia_j)σ(A) = \displaystyle\prod\_{i=0}^{n-1}\prod\_{j=i+1}^{n-1}{(a\_i - a\_j)}.

There is a direct isomorphism between pairs of sequences and sequences of pairs. Formally: Let A,BS_nA, B ∈ S\_n. We can denote their elements as follows: A=(a_0,,a_n1)A = (a\_0, \dots , a\_{n-1}), B=(b_0,,b_n1)B = (b\_0, \dots , b\_{n-1}). The corresponding sequence of pairs ((a_0,b_0),,(a_n1,b_n1))\left((a\_0, b\_0), \dots ,(a\_{n-1}, b\_{n-1})\right) will be denoted P_A,BP\_{A,B}.

Pairs of integers can be ordered lexicographically in the usual fashion: (a,b)(c,d)(a, b) ≤ (c, d) if either a<ca < c, or (a=cbda = c ∧ b ≤ d). A sequence P=(p_0,,p_n1)P = (p\_0, \dots , p\_{n-1}) of pairs of integers is ordered lexicographically if for all ii, p_ip_i+1p\_i ≤ p\_{i+1}. Let ρ(P)=ρ(P) = [if PP is ordered lexicographically then 11 else 00].

Let MM be a n×nn \times n matrix, with rows and columns indexed from 00 to n1n - 1. Elements of MM will be denoted m_r,cm\_{r,c}. A matrix is called a Z\mathbb{Z}-var matrix if each element in the matrix is either an integer or a variable. The nn-step traversal weight of MM is the following value

φ(M)=1d_n12_A=(a_0,,a_n1),AS_B=(b_0,,b_n1),BS(ρ(P_A,B)ρ(A)ρ(B)_i=0n1m_a_i,b_i)φ(M) = \frac{1}{d\_{n-1}^2} \cdot \sum\_{A=(a\_0,\dots ,a\_{n-1}), A∈S} \sum\_{B=(b\_0,\dots ,b\_{n-1}), B∈S} \left( ρ\left(P\_{A,B}\right) \cdot \left|ρ(A) \right| \cdot ρ(B) \cdot \prod\_{i=0}^{n-1}{m\_{a\_i,b\_i}}\right)

Given is a multivariate polynomial pp with integer coefficients. Produce any reasonably small Z\mathbb{Z}-var matrix MM such that φ(M)=pφ(M) = p.

입력

The first line of the input file contains an integer tt specifying the number of test cases. Each test case is preceded by a blank line.

Each test case consists of a single line describing the polynomial. The variables are the letters a through z, the syntax will be clear from the input file. Each polynomial in the input file contains less than 5050 operations (i.e., additions, subtractions and multiplications)

출력

For each test case output one matrix in the following format: First its size nn, then all its elements in row major order. The elements may be separated by any positive amounts of whitespace. The size of the matrix must not exceed 7070. All integers must be between 109-10^9 and 10910^9, inclusive.

If for a given polynomial no such matrix exists, output a single zero instead