Magic Squares
InterviewTime limit1sMemory limit256 MB
Check each test case square by comparing every row, column, and both diagonal sums and report whether it is magic.
- Level
Easy2 of 10
- Topics
- Matrix, Simulation
- Solved
- No attempts yet
Problem
A magic square is an arrangement of integers in a square grid where the sum of each row, each column, and both main diagonals is the same. The grid has equal numbers of rows and columns. Let denote the side length, so the square contains integers. The figure below shows a magic square with .

Input
The first line contains a positive integer , the number of test cases. Each test case begins with an integer , the side length of the square. The next lines each contain integers separated by one or more spaces.
Output
For each test case, if the square is a magic square, print Magic square of size m, where is the number of rows. Otherwise print Not a magic square.