Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef has an integer $N$ and he wants to generate a matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). He thinks that $M$ would be *delicious* if:
Each element of this matrix is an integer between $1$ and $N^{2}$ inclusive.
All the elements of the matrix are pairwise distinct.
For each square submatrix containing cells in rows $r$ through $r+a$ and in columns $c$ through $c+a$ (inclusive) for some valid integers $r$, $c$ and $a ≥ 0$:
- $M_{r,c} + M_{r+a,c+a}$ is even
- $M_{r,c+a} + M_{r+a,c}$ is even

Can you help Chef generate a delicious matrix? It can be proved that a solution always exists. If there are multiple solutions, you may find any one.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains a single integer $N$.

------  Output ------
For each test case, print $N$ lines describing a delicious matrix $M$. For each valid $i$, the $i$-th of these lines should contain $N$ space-separated integers $M_{i,1}, M_{i,2}, \ldots, M_{i,N}$.

------  Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 10^{3}$
the sum of $N$ over all test cases does not exceed $10^{3}$

------  Subtasks ------
Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
1

2
----- Sample Output 1 ------ 
1 2

4 3
----- explanation 1 ------ 
Example case 1: The matrix $M$ has five square submatrices. Four of them ($[1]$, $[2]$, $[4]$, $[3]$) have $a=0$, so they obviously satisfy all conditions. The last square submatrix is the whole matrix $M$, with $r=c=a=1$, and we can see that $M_{1,1} + M_{2,2} = 1 + 3 = 4$ and $M_{1,2} + M_{2,1} = 2 + 4 = 6$ are both even.

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	n = int(input())
	a = []
	x = 1
	for i in range(n):
		m = []
		for j in range(n):
			m.append(x)
			x += 1
		if i % 2 == 1:
			a.append(m[::-1])
		else:
			a.append(m)
	for i in a:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	s = 0
	for i in range(1, n * n + 1, n):
		l = [i for i in range(i, n + i)]
		if s == 1:
			l.sort(reverse=True)
			print(*l)
		else:
			print(*l)
		if l[-1] % 2 == 0:
			s = 1
		else:
			s = 0


for i in range(int(input())):
	n = int(input())
	a = list()
	fill = 1
	for j in range(1, n + 1):
		b = list()
		for k in range(1, n + 1):
			b.append(fill)
			fill += 1
		if j % 2 == 0:
			a.append(b[::-1])
		else:
			a.append(b)
	for k in a:
		print(*k)


for _ in range(int(input())):
	n = int(input())
	matrix = []
	fill = 1
	for i in range(1, n + 1):
		temp = []
		for j in range(1, n + 1):
			temp.append(fill)
			fill += 1
		if i % 2 == 0:
			matrix.append(temp[::-1])
		else:
			matrix.append(temp)
	for i in matrix:
		print(*i)


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2 == 1:
		for i in range(n):
			ans = ''
			for j in range(n):
				ans += str(j + i * n + 1) + ' '
			print(ans[:-1])
	else:
		for i in range(n):
			ans = ''
			if i % 2 == 0:
				for j in range(n):
					ans += str(j + i * n + 1) + ' '
			elif i % 2 == 1:
				j = n - 1
				while j >= 0:
					ans += str(j + i * n + 1) + ' '
					j -= 1
			print(ans[:-1])


t = int(input())
for i in range(t):
	n = int(input())
	a = 0
	for i in range(n):
		temp = []
		for j in range(n):
			if i % 2 == 0:
				a += 1
			temp.append(a)
			if i % 2 != 0:
				a -= 1
		print(*temp)
		a = a + n


t = int(input())
for i in range(t):
	n = int(input())
	a = 0
	for j in range(n):
		l = []
		for k in range(n):
			if j % 2 == 0:
				a += 1
			l.append(a)
			if j % 2 != 0:
				a -= 1
		print(*l)
		a = a + n


t = int(input())
for _ in range(t):
	n = int(input())
	a = [i for i in range(1, n * n + 1)]
	count = 0
	condition = n * n
	while condition > 0:
		print(*a[count:count + n])
		count += n
		condition -= n
		b = a[count:count + n]
		b.reverse()
		count += n
		print(*b)
		condition -= n


for _ in range(int(input())):
	n = int(input())

	def row(y, f):
		x = y - n
		ans = [i for i in range(x + 1, y + 1)]
		if f:
			return ans
		else:
			return ans[::-1]
	m = [row(n * i, i % 2 == 1) for i in range(1, n + 1)]
	for r in m:
		print(*r)


def run():
	T = int(input())
	for _ in range(T):
		input_ = int(input())
		print(f(input_))

def f(N):
	ans = [[r * N + c + 1 for c in range(N)] for r in range(N)]
	if N % 2 == 0:
		for i in range(1, N, 2):
			ans[i] = ans[i][::-1]
	ans = [' '.join(map(str, row)) for row in ans]
	ans = '\n'.join(ans)
	return ans
run()


tc = int(input())
for _ in range(tc):
	n = int(input())
	res = []
	flag = False
	if n % 2 == 0:
		flag = True
	for i in range(n):
		x = list(range(i * n + 1, (i + 1) * n + 1))
		if flag and i % 2 == 1:
			x.reverse()
		res.append(x)
	for i in res:
		print(*i, sep=' ')


t = int(input())
for _ in range(t):
	n = int(input())
	boo = True
	for i in range(1, n * n + 1, n):
		if boo:
			print(*[x + i for x in range(0, n)])
		else:
			print(*[x + i for x in range(n - 1, -1, -1)])
		boo = not boo


t = int(input())
for inh in range(0, t):
	n = int(input())
	if n % 2 == 1:
		(m, j) = (1, 1)
		while m <= n:
			k = m * n
			while j <= k:
				print(j, end=' ')
				j += 1
			print('')
			m += 1
	else:
		(m, j) = (1, 1)
		while m <= n:
			k = m * n
			a = []
			while j <= k:
				a.append(j)
				j += 1
			if m % 2 == 0:
				a.reverse()
			print(*a)
			m += 1


try:
	for _ in range(int(input())):
		N = int(input())
		k = 1
		for i in range(N):
			L = [None] * N
			if i & 1 == 0:
				for x in range(N):
					L[x] = k
					k += 1
			else:
				for x in range(N):
					L[N - x - 1] = k
					k += 1
			print(*L)
except Exception as e:
	print(e.__class__)


for _ in range(int(input())):
	n = int(input())
	dp = [[0 for x in range(n)] for y in range(n)]
	odd = 1
	even = 2
	for i in range(n):
		for j in range(n):
			if (i + j) % 2 == 0:
				dp[i][j] = odd
				odd = odd + 2
			else:
				dp[i][j] = even
				even = even + 2
	for po in dp:
		print(*po)


t = int(input())
while t:
	t -= 1
	n = int(input())
	dp = [[0 for x in range(n)] for y in range(n)]
	if n & 1 == 0:
		for i in range(len(dp)):
			for j in range(len(dp)):
				if i & 1 == 0:
					dp[i][j] = n * i + 1 + j
				else:
					dp[i][j] = n * (i + 1) - j
	else:
		for i in range(len(dp)):
			for j in range(len(dp)):
				dp[i][j] = n * i + 1 + j
	for k in dp:
		print(*k)


for _ in range(int(input())):
	size = int(input())
	n = 1
	for i in range(size):
		mat = []
		for j in range(size):
			mat.append(n)
			n += 1
		if i & 1:
			print(*mat[::-1])
		else:
			print(*mat)


def evenm(n):
	a = []
	tn = 0
	start = 1
	for k in range(n):
		temp = []
		for t in range(n):
			temp.append(start)
			start += 1
		if tn == 0:
			a.append(temp)
			tn = 1
		else:
			a.append(temp[::-1])
			tn = 0
	return a
t = int(input())
for i in range(t):
	n = int(input())
	a = evenm(n)
	for j in a:
		print(*j)


for _ in range(int(input())):
	n = int(input())
	if n & 1 == 1:
		for i in range(n):
			ans = range(n * i + 1, n * i + n + 1)
			print(' '.join(map(str, ans)))
	else:
		for i in range(n):
			if i & 1 == 0:
				ans = range(n * i + 1, n * i + n + 1)
			else:
				ans = [j + 1 if j & 1 == 1 else j - 1 for j in range(n * i + 1, n * i + n + 1)]
			print(' '.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	c = 1
	for i in range(1, n + 1):
		if i % 2 != 0:
			for j in range(c, c + n - 1):
				print(c, end=' ')
				c += 1
			print(c)
			c += 1
		else:
			s = ''
			for j in range(c, c + n):
				a = str(c) + ' ' + s
				s = a
				a = ''
				c += 1
			print(s)


T = int(input())
while T > 0:
	N = int(input())
	T = T - 1
	k = 1
	for i in range(N):
		L = []
		if i % 2 == 0:
			for x in range(N):
				L.append(k)
				k = k + 1
		else:
			for x in range(N):
				L.insert(0, k)
				k = k + 1
		print(*L)


t = int(input())
while t > 0:
	n = int(input())
	res = [[0] * n for i in range(n)]
	at = [[] for i in range(n + n)]
	for i in range(n):
		for j in range(n):
			at[i + j].append((i, j))
	ptr = 1
	for i in range(n + n):
		for pos in at[i]:
			if (pos[0] + pos[1]) % 2 == 0:
				res[pos[0]][pos[1]] = ptr
				ptr += 2
	ptr = 2
	for i in range(n + n):
		for pos in at[i]:
			if (pos[0] + pos[1]) % 2 != 0:
				res[pos[0]][pos[1]] = ptr
				ptr += 2
	for i in range(n):
		print(' '.join(map(str, res[i])))
	t -= 1


import sys
import math

def main(n):
	m = [[0] * n for i in range(n)]
	start = 1
	for i in range(n):
		m[0][i] = start
		start += 1
	for i in range(1, n):
		for j in range(n):
			m[i][j] = n + m[i - 1][j]
	if n % 2 == 0:
		for i in range(1, n):
			if i % 2:
				(p, q) = (0, n - 1)
				while p < q:
					(m[i][p], m[i][q]) = (m[i][q], m[i][p])
					p += 1
					q -= 1
	for e in m:
		print(*e)
	return
for _ in range(int(input())):
	n = int(input())
	main(n)


t = int(input())
while t:
	t -= 1
	n = int(input())
	matrix = []
	for i in range(n):
		matrix.append([i * n + j for j in range(1, n + 1)])
	if n & 1 == False:
		for i in range(1, n, 2):
			matrix[i] = matrix[i][::-1]
	for c in matrix:
		print(*c)