Sarthak and his Magic Grid CodeChef Solution – Queslers

Problem: Sarthak and his Magic Grid CodeChef Solution

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

  • 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.

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.


  • 1≤T≤1001≤T≤100
  • 1≤N≤1001≤N≤100

Sample Input 1 


Sample Output 1 

1 1 1
1 1 1
1 1 1


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

Sarthak and his Magic Grid CodeChef Solution Review:

In our experience, we suggest you solve this Sarthak and his Magic Grid CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Sarthak and his Magic Grid Problem is available on Hacker Rank for Free, if you are stuck anywhere between a compilation, just visit Queslers to get Sarthak and his Magic Grid CodeChef Solution.


I hope this Sarthak and his Magic Grid CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More on Queslers >>

CodeChef Solution

Cognitive Class Answers

Leetcode Solution

Coursera Quiz Answers

Leave a Reply

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