#P1521E. Nastia and a Beautiful Matrix
Nastia and a Beautiful Matrix
No submission language available for this problem.
Description
You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing?
Let be how many numbers () you have.
An matrix is called beautiful if it contains all the numbers you have, and for each submatrix of the original matrix is satisfied:
- The number of occupied cells doesn't exceed ;
- The numbers on each diagonal are distinct.
Make a beautiful matrix of minimum size.
The first line contains a single integer () — the number of test cases.
The first line of each test case contains integers and () — how many numbers Nastia gave you and the length of the array , respectively.
The second line of each test case contains integers (, ), where is how many numbers you have.
It's guaranteed that the sum of and in one test doesn't exceed .
For each test case print a single integer — the size of the beautiful matrix.
In the next lines print integers (; if position is empty, print ) — the beautiful matrix you made up.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains integers and () — how many numbers Nastia gave you and the length of the array , respectively.
The second line of each test case contains integers (, ), where is how many numbers you have.
It's guaranteed that the sum of and in one test doesn't exceed .
Output
For each test case print a single integer — the size of the beautiful matrix.
In the next lines print integers (; if position is empty, print ) — the beautiful matrix you made up.
Samples
Note
Note that in this problem represents a blank, not a number.
Examples of possible answers for the first test case:
$\begin{array}{cc} 1 & 1 \\ 4 & 0 \\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 4 \\ 1 & 0 \\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 0 \\ 1 & 1 \\ \end{array}$
Examples of not beautiful matrices for the first test case:
$\begin{array}{cc} 1 & 0 \\ 4 & 1 \\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 1 \\ 7 & 1 \\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 0 \\ 4 & 0 \\ \end{array}$
The example of the not beautiful matrix for the second test case:
Everything is okay, except the left-top submatrix contains numbers.