Problem7997--CodeChef DISTMAT - Distinct Matrix

7997: CodeChef DISTMAT - Distinct Matrix

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB  Special Judge

Description

You are given an integer N. Generate a matrix of size N×N such that:
  • Each element of the matrix is either 0 or 1;
  • All rows (from left to right) and all columns (from top to bottom) are distinct.
    In other words, the 2⋅N strings, that are obtained from the rows and columns of the matrix, are all distinct.
If multiple such matrices exist, print any. If no such matrix exists, print −1 instead.

Input

The first line of input will contain a single integer T, denoting the number of test cases.
Each test case consists of a single integer N, the length of the row and column of matrix.

Output

For each test case, output N lines, where each line contains a binary string of length N, such that the matrix satisfies the given conditions.
If no such matrix exists, print −1.

Constraints

1≤T≤100
2≤N≤1000
The sum of N over all test cases won't exceed 6000.

Sample 1 Input

3
4
2
5

Sample 1 Output

1010
1110
1001
1011
-1
00101
11010
01110
11001
01011
Test case 1: The rows of the matrix are {1010,1110,1001,1011}. The columns of the matrix are {1111,0100,1101,0011}.
The set of all rows and columns are {1010,1110,1001,1011,1111,0100,1101,0011}. Note that all elements of the set containing all rows and columns are distinct. Thus, the matrix satisfies the conditions.
Test case 2: It can be proven that no binary matrix of size 2×2 is valid.

HINT

相同题目:CodeChef DISTMAT

Source/Category