#K80397. Matrix Construction

    ID: 35521 Type: Default 1000ms 256MiB

Matrix Construction

Matrix Construction

In this problem, you are given an integer (n) and you need to construct an (n\times n) matrix. The matrix should be constructed such that every element is (-1) except for the main diagonal which must be (1). That is, for each cell ((i,j)), the value is defined as:

[ A_{i,j} = \begin{cases} 1, & \text{if } i = j \ -1, & \text{if } i \neq j \end{cases} ]

For example, when (n=2), the matrix will be:

1 -1 -1 1

Note that the output for each test case should be printed in the same format as shown in the examples, with each row on a new line and a blank line separating matrices from different test cases.

inputFormat

The input is given via standard input (stdin). The first line contains an integer (T) representing the number of test cases. Each of the following (T) lines contains a single integer (n) representing the size of the matrix to construct.

outputFormat

For each test case, output the corresponding (n\times n) matrix. Each row of the matrix should be printed on a separate line with the elements separated by a single space. Print a blank line between outputs of different test cases. The output should be written to standard output (stdout).## sample

3
2
3
4
1 -1

-1 1

1 -1 -1 -1 1 -1 -1 -1 1

1 -1 -1 -1 -1 1 -1 -1 -1 -1 1 -1 -1 -1 -1 1

</p>