Sarthak and his Magic Grid solution codechef- Sarthak got an empty magic grid of size N×NN×N on his birthday. The grid can only be filled with positive integers such that the bitwise XOR of all numbers from any row, any column, or any of the two main diagonals must all be the same! Can you help Sarthak fill this grid using only positive integers no more than 109109?

Sarthak and his Magic Grid solution codechef

Sarthak got an empty magic grid of size N×NN×N on his birthday. The grid can only be filled with positive integers such that the bitwise XOR of all numbers from any row, any column, or any of the two main diagonals must all be the same! Can you help Sarthak fill this grid using only positive integers no more than 109109?

Input Format Sarthak and his Magic Grid solution codechef

  • The first line of each input contains TT – the number of test cases. The test cases then follow.
  • The only line of each test case contains an integer NN – the size of the grid.

Sarthak and his Magic Grid solution codechef Output Format

For each test case, output NN lines, each containing NN space-separated integers, such that the grid satisfies the condition given in the statement.

Each integer should be positive and 109≤109.

Constraints

  • 1T1001≤T≤100
  • 1N1001≤N≤100

Sample Input 1 Sarthak and his Magic Grid solution codechef

1
3

Sample Output 1 

1 2 3 
3 1 2
2 3 1

Explanation Sarthak and his Magic Grid solution codechef

The bitwise XOR of all rows, columns and main diagonals in the grid is 00. Therefore, this satisfies the condition.

Leave a Comment

Your email address will not be published. Required fields are marked *