#K6281. Constructing Equal Sum Matrices

    ID: 31614 Type: Default 1000ms 256MiB

Constructing Equal Sum Matrices

Constructing Equal Sum Matrices

You are given a single integer (N) and need to construct an (N \times N) matrix such that:

  1. The sum of the elements in each row is equal.
  2. The sum of the elements in each column is equal.
  3. Every element in the matrix is an integer greater than or equal to 0.

A valid solution is to fill the matrix with ones since for any positive (N), each row and column will sum to (N). However, if (N \le 0), it is impossible to construct such a matrix and you should output -1.

Formally, for (N > 0), output an (N \times N) matrix (A) where (A_{ij} = 1) for all (1 \leq i, j \leq N). For (N \le 0), output -1.

Note: All formulas above are formatted in (\LaTeX).

inputFormat

The input is read from standard input (stdin). The first line contains an integer (T), the number of test cases. Each of the following (T) lines contains a single integer (N).

outputFormat

For each test case, if (N \le 0) output a single line with -1. Otherwise, output the constructed (N \times N) matrix. Each row of the matrix should be printed on a new line with its elements separated by a single space. The output for each test case should follow immediately after the previous test case's output without any extra blank lines.## sample

1
2
1 1

1 1

</p>