Irrational Root

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Vietnamese as well.
It is wellknown that ∑sqrt(a_{i}), a_{i} ∈ N is a root of some integercoefficient polynomial. For example: sqrt(2) is a root of polynomial: x^{2} − 2. Now, your task is to find not only such polynomial but also the minimal one. When comparing two polynomials, firstly, we consider their degree and then the coefficient of the highest term, and then the second highest term and so on.
(Note that we consider only polynomial with the coefficient of highest term is positive)Input
First line contains an integer T denotes the number of testcases. Each testcase is described by an integer n and followed by n spaceseperated integers a_{i}.
Output:
Each testcase print an integer k denotes the degree of polynomial in a single line. Then next line print k + 1 spaceseperated integers modolo 10^{9} + 7, coefficients from lowest to highest term.
Constraints
1 ≤ T ≤ 5, 1 ≤ n ≤ 15
a_{i} are n distinct primes, 1 ≤ a_{i} ≤ 10^{9}
Subtasks
 Subtask #1: (10 points): n ≤ 3
 Subtask #2: (20 points): n ≤ 5
 Subtask #3: (30 points): n ≤ 10
 Subtask #4: (40 points): n ≤ 15
Example
Input:2 1 2 2 2 3
Output:2 1000000005 0 1 4 1 0 999999997 0 1
Explanation
The first polynomial is x^{2} − 2, and the second one is x^{4} − 10x^{2} + 1.
Author:  chemthan 
Editorial  https://discuss.codechef.com/problems/APRPS 
Tags  chemthan, fft, hard, july17, math, ntt 
Date Added:  7022017 
Time Limit:  4 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 