#K48037. Snake Pattern Matrix
Snake Pattern Matrix
Snake Pattern Matrix
Given an integer (N), generate an (N \times N) matrix filled with consecutive integers from 1 to (N^2) arranged in a snake-like pattern. In this pattern, rows with an odd index (starting with 0 as the first row) are filled left-to-right, and rows with an even index are reversed (i.e. right-to-left). For example, when (N = 2), the resulting matrix is:1 2
4 3
and when (N = 3) it is:1 2 3
6 5 4
7 8 9
Your task is to implement this functionality for multiple test cases.
inputFormat
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 dimension of the matrix.
outputFormat
For each test case, output the corresponding snake pattern matrix. Each row of the matrix must be printed on a new line with space-separated values. Separate the output of different test cases with an empty line.## sample
1
1
1