Consider the following $4 \times 4$ pattern:
1  2  4  7
3  5  8 11
6  9 12 14
10 13 15 16

You are given an integer $N$. Print the $N \times N$ pattern of the same kind (containing integers $1$ through $N^2$).

-----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; each of them should contain $N$ space-separated integers.

-----Constraints-----
- $1 \le T \le 10$
- $1 \le N \le 100$

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

-----Example Input-----
1
4

-----Example Output-----
1 2 4 7
3 5 8 11
6 9 12 14
10 13 15 16

-----Explanation-----

Difficulty: EASY

Solutions:
for i in range(int(input())):
	n = int(input())
	arr = [[0] * n for j in range(n)]
	c = 1
	for j in range(n):
		for k in range(j + 1):
			arr[k][j - k] = c
			c += 1
	for j in range(1, n):
		for k in range(n - j):
			arr[j + k][n - k - 1] = c
			c += 1
	for j in arr:
		print(*j)


import numpy as np
for _ in range(int(input())):
	n = int(input())
	oxx = np.zeros((n, n))
	(i, pp, c) = (0, 0, 0)
	while i <= n - 1 and pp <= n - 1:
		tempi = i
		temppp = pp
		while tempi <= pp:
			c += 1
			oxx[tempi][temppp] = int(c)
			temppp -= 1
			tempi += 1
		if pp != n - 1:
			i = 0
			pp += 1
		else:
			i += 1
			pp = n - 1
	for i in range(n):
		print(*list(map(int, oxx[i])))


import math as m

def ncr(N, R):
	return m.factorial(N) // (m.factorial(R) * m.factorial(N - R))

def getL():
	return [int(i) for i in input().split(' ')]

def getInt():
	return int(input())

def solve():
	n = int(input())
	arr = []
	for i in range(n):
		for j in range(n):
			arr += [[i + j, i, j]]
	arr = sorted(arr, key=lambda x: x[0])
	ans = [[0 for i in range(n)] for j in range(n)]
	count = 1
	for v in arr:
		ans[v[1]][v[2]] = count
		count += 1
	for j in ans:
		print(*j)
for _ in range(getInt()):
	solve()


for _ in range(int(input())):
	n = int(input())
	tm = 1
	mat = [[0 for j in range(n)] for i in range(n)]
	for i in range(n):
		k = 0
		l = i
		while l > -1:
			mat[k][l] = tm
			tm += 1
			k += 1
			l -= 1
	for i in range(1, n):
		k = i
		l = n - 1
		while k < n:
			mat[k][l] = tm
			tm += 1
			k += 1
			l -= 1
	for i in mat:
		print(*i)


for test_ in range(int(input())):
	n = int(input())
	op = [[0 for i in range(n)] for i in range(n)]
	i = 0
	j = 0
	num = 1
	while i < n and j < n:
		temp1 = i
		temp2 = j
		while temp1 <= j:
			op[temp1][temp2] = num
			num += 1
			temp1 += 1
			temp2 -= 1
		if j != n - 1:
			i = 0
			j += 1
		else:
			i += 1
			j = n - 1
	for i in op:
		print(*i)


for _ in range(int(input())):
	x = int(input())
	t = 0
	for i in range(1, x + 1):
		t = t + i
		m = [t]
		n = t
		for l in range(i, i + x - 1):
			if l < x:
				a = n + l
			else:
				a = n + (2 * x - l - 1)
			m.append(a)
			n = a
		print(*m)


for _ in range(int(input())):
	n = int(input())
	a = [[0 for j in range(n)] for i in range(n)]
	ans = 1
	temp = 0
	for i in range(n):
		for j in range(n):
			if i == 0:
				a[i][j] = ans + temp
				ans = a[i][j]
				temp += 1
			if j != n - 1 and i != 0:
				a[i][j] = a[i - 1][j + 1] + 1
			if j == n - 1 and i != 0:
				a[i][j] = a[i - 1][j] + temp
				temp -= 1
	for k in a:
		print(*k)


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


t = int(input())
for x in range(t):
	n = int(input())
	c = 0
	for i in range(1, n + 1):
		c += i
		l = [c]
		m = c
		for o in range(i, n + i - 1):
			if o < n:
				b = m + o
			else:
				b = m + (2 * n - o - 1)
			l.append(b)
			m = b
		print(*l)


t = int(input())
while t > 0:
	n = int(input())
	l = []
	for i in range(n):
		l1 = []
		for j in range(n):
			l1.append(0)
		l.append(l1)
	c = 1
	for j in range(n):
		k = 0
		for i in range(j, -1, -1):
			l[k][i] = c
			c += 1
			k += 1
	for i in range(1, n):
		m = i
		for j in range(n - i):
			l[m][n - j - 1] = c
			c += 1
			m += 1
	for p in l:
		print(*p)
	t -= 1


for i in range(int(input())):
	n = int(input())
	st = 0
	for i in range(1, n + 1):
		st = st + i
		l = [st]
		k = st
		for j in range(i, n + i - 1):
			if j < n:
				x = k + j
			else:
				x = k + (2 * n - j - 1)
			l.append(x)
			k = x
		print(*l)


for i in range(int(input())):
	n = int(input())
	k = [[0 for j in range(n)] for i in range(n)]
	k[0][0] = 1
	r = 0
	c = 1
	p = 1
	for i in range(2, n * n + 1):
		if r == n - 1:
			k[r][c] = i
			r = c + 1
			c = n - 1
		elif r == p:
			k[r][c] = i
			p += 1
			r = c
			c = p
		else:
			k[r][c] = i
			r += 1
			c -= 1
	for i in k:
		print(' '.join(map(str, i)))


for _ in range(int(input())):
	n = int(input())
	matrix = [[0 for _ in range(n)] for _ in range(n)]
	cnt = 1
	matrix[0][0] = 1
	matrix[n - 1][n - 1] = n * n
	for i in range(1, n):
		r = 0
		c = i
		while r < n and c >= 0:
			cnt += 1
			matrix[r][c] = cnt
			r += 1
			c -= 1
	for i in range(1, n):
		r = i
		c = n - 1
		while r < n and c >= 0:
			cnt += 1
			matrix[r][c] = cnt
			r += 1
			c -= 1
	for i in range(n):
		for j in range(n - 1):
			print(matrix[i][j], end=' ')
		print(matrix[i][n - 1])


try:
	for _ in range(int(input())):
		N = int(input())
		X = list(range(1, N + 1)) + list(range(N - 1, 0, -1))
		A = [[] for i in range(N)]
		count = 1
		start = 0
		for x in range(len(X)):
			if x > N - 1:
				start += 1
			for i in range(start, start + X[x]):
				A[i].append(count)
				count += 1
		for a in A:
			print(*a)
except:
	pass


for _ in range(int(input())):
	n = int(input())
	ans = [[0] * n] * n
	c = 1
	for i in range(n):
		for j in range(i + 1):
			d = ans[j].copy()
			d[i - j] = c
			ans[j] = d.copy()
			c += 1
	for i in range(1, n):
		for j in range(n - i):
			d = ans[i + j].copy()
			d[n - j - 1] = c
			ans[i + j] = d.copy()
			c += 1
	for i in ans:
		print(*i)


for i in range(int(input())):
	t = int(input())
	n = 0
	for i in range(1, t + 1):
		n = n + i
		x = [n]
		y = n
		for j in range(i, t + i - 1):
			if j < t:
				z = y + j
			else:
				z = y + (2 * t - j - 1)
			x.append(z)
			y = z
		print(*x)


n_sum = [0]
for n in range(1, 100):
	n_sum.append(n * (n + 1) // 2)
tests = int(input())
for i in range(tests):
	n = int(input())
	ans_arr = []
	for j in range(n):
		temp_arr = []
		for k in range(n):
			if j + k < n:
				add = n_sum[j + k]
				temp_arr.append(add + j + 1)
			else:
				diff = j + k - n + 1
				temp_arr.append(temp_arr[k - 1] + n - diff)
		ans_arr.append(temp_arr)
	for x in ans_arr:
		print(*x)


try:
	T = int(input())
	P = ''
	for i in range(T):
		N = int(input())
		A = [[0 for i in range(N)] for j in range(N)]
		a = 1
		K = 0
		for x in range(2 * N):
			if K < N:
				i = 0
				j = K
				for y in range(K + 1):
					if i + j == K and i >= 0 and (j >= 0):
						A[i][j] = a
						i = i + 1
						j = j - 1
						a = a + 1
				K = K + 1
			else:
				J = N - 1
				I = K - J
				for y in range(2 * N - K - 1):
					A[I][J] = a
					I = I + 1
					J = J - 1
					a = a + 1
				K = K + 1
		for a in range(0, N):
			for b in range(0, N):
				if b != N - 1:
					P = P + str(A[a][b]) + ' '
				else:
					P = P + str(A[a][N - 1]) + '\n'
	print(P)
except:
	pass


for T in range(0, int(input())):
	if T <= 10:
		N = int(input())
		if N <= 100:
			L1 = [[0 for i in range(0, N)] for j in range(0, N)]
			c = 1
			for i in range(0, N):
				a = 0
				for j in range(i, -1, -1):
					L1[a][j] = c
					c += 1
					a += 1
			for x in range(1, N):
				k = x
				for y in range(N - x):
					L1[k][N - y - 1] = c
					c += 1
					k += 1
			for mat in L1:
				print(*mat)


t = int(input())
for i in range(t):
	n = int(input())
	k = 1
	q = [None] * n
	for i in range(n):
		k += i
		q[i] = k
	print(*q)
	for i in range(n - 1):
		for j in range(n - 1):
			q[j] = q[j + 1] + 1
		q[n - 1] = q[n - 2] + (n - i - 1)
		print(*q)


for _ in range(int(input())):
	n = int(input())
	li = []
	for i in range(n):
		li.append([0] * n)
	li[0][0] = 1
	c = 2
	for i in range(1, n):
		for j in range(i + 1):
			li[j][i - j] = c
			c += 1
	for i in range(1, n):
		k = n - 1
		for j in range(i, n):
			li[j][k] = c
			k -= 1
			c += 1
	for i in li:
		print(*i)