Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 

Chef has finished his freshman year in college. As a present, his parents gave him a new problem to solve:

Chef has to fill a K x K square grid of integers in a certain way. Let us say that such a grid is valid if:
Each cell contains an integer from 1 and K (inclusive). 
No integer appears twice in the same row or the same column.

Let F(K) be maximum possible distance between the center of the square and the closest cell that contains 1, among all possible squares with the side length K.

Here, we use the following notions:
The distance between cell (x, y) and (i, j) is equal to |x-i|+|y-j|. 
The center of a K x K square is cell ((K+1)/2, (K+1)/2) for odd K. 

------ Input ------ 

The first line of input contains a single integer T denoting the number of test cases.

Each test case consists of a single line containing a single odd integer K.

------ Output ------ 

For each test case, print K lines each consisting of K space separated integers giving some square grid where the distance from the center of the grid to the nearest 1 is exactly F(K). If there's more than 1 possible answer output any of them.

------ Constraints ------ 

$K_{i} is odd.$
Subtask #1 (10 points)  :
$ 1 ≤ T ≤ 50  $
$ 1 ≤ K_{i}≤ 5 $ 
Subtask #1 (90 points)  :
$ 1 ≤ T ≤ 10  $
$ 1 ≤ K_{i} < 400 $ 

----- Sample Input 1 ------ 
2
1
3
----- Sample Output 1 ------ 
1
3 2 1
1 3 2
2 1 3

Difficulty: MEDIUM
Tags: Implementation

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	l = [[0 for i in range(n)] for j in range(n)]
	c = (n + 1) // 2
	for i in range(n // 2 + 1):
		l[c - 1 + i][i] = 1
	for i in range(n // 2):
		l[i][c + i] = 1
	for i in range(n):
		e = l[i].index(1)
		for j in range(1, n):
			l[i][e - j] = j + 1
	for i in range(n):
		print(*l[i])


for _ in range(int(input())):
	k = int(input())
	mat = [[0 for i in range(k)] for j in range(k)]
	mat[k // 2] = [i for i in range(1, k + 1)]
	z = [i for i in range(1, k + 1)]
	j = 1
	for i in range(k // 2 + 1, k, 1):
		mat[i] = z[j:] + z[:j]
		j += 1
	j = k - 1
	for i in range(k // 2 - 1, -1, -1):
		mat[i] = z[j:] + z[:j]
		j -= 1
	for i in range(k):
		print(*mat[i])


t = int(input())
for i in range(t):
	n = int(input())
	m = [[0 for x in range(n)] for y in range(n)]
	m[n // 2] = [x for x in range(1, n + 1)]
	z = [x for x in range(1, n + 1)]
	c = 1
	for j in range(n // 2 + 1, n, 1):
		m[j] = z[c:] + z[:c]
		c += 1
	c = n - 1
	for k in range(n // 2 - 1, -1, -1):
		m[k] = z[c:] + z[:c]
		c -= 1
	for z in range(n):
		print(*m[z])


def func_arr(n, x):
	sol_arr = [0] * n
	for i in range(1, n + 1):
		sol_arr[(i + x - 1) % n - 1] = i
	return sol_arr
t = int(input())
while t > 0:
	n = int(input())
	if n == 1:
		print(1)
	else:
		for i in range((n + 1) // 2, 0, -1):
			print(*func_arr(n, i))
		for i in range(n - 1, (n + 1) // 2, -1):
			print(*func_arr(n, i))
		print(*func_arr(n, n))
	t -= 1


for _ in range(int(input())):
	k = int(input())
	mat = [[0] * k for _ in range(k)]
	start = (k + 1) // 2
	for i in range(k):
		for j in range(k):
			val = (start + j) % k
			if val == 0:
				val = k
			mat[i][j] = val
		start -= 1
		if start == 0:
			start = k
	for item in mat:
		print(*item)


from collections import deque
for i in range(int(input())):
	a = deque()
	n = int(input())
	for i in range(1, n + 1):
		a.appendleft(i)
	if n == 1:
		print(1)
		continue
	k = n // 2
	b = a.copy()
	for i in range(n):
		for j in range(n):
			if a[j] == k:
				a[j] = 1
			elif a[j] == 1:
				a[j] = k
			print(a[j], end=' ')
		b.rotate()
		a = b.copy()
		print()


t = int(input())
for _ in range(t):
	k = int(input())
	row = [i for i in range(1, k + 1)]
	row = row[k // 2 + 1:] + row[:k // 2 + 1]
	for i in range(1, k + 1):
		for j in row:
			print(j, end=' ')
		print()
		row = row[1:] + row[0:1]


for e in range(int(input())):
	n = int(input())
	l = [e for e in range(1, n + 1)]
	if n != 1:
		(l[0], l[n // 2 + 1]) = (l[n // 2 + 1], l[0])
	for i in range(n):
		print(*l)
		l = [l[-1]] + l
		l.pop(-1)


import sys
t = int(input())
while t:
	k = int(input())
	h = int(k / 2)
	for i in range(k):
		for j in range(k):
			x = (h + j - i) % k + 1
			x = k + x if x < 0 else x
			sys.stdout.write(str(x) + ' ')
		sys.stdout.write('\n')
	t -= 1


t = int(input())
for i in range(t):
	k = int(input())
	p = (k - 1) // 2
	if k == 1:
		print(1)
	else:
		for i in range(k):
			l = k + 1 - p
			for j in range(k):
				if j == k - 1:
					print(l)
				else:
					print(l, end=' ')
				if l == k:
					l = 1
				else:
					l += 1
			if p > 0:
				p -= 1
			if i == (k - 1) // 2 - 1:
				p = k


for t in range(int(input())):
	n = int(input())
	row = list(range(1, n + 1))[n // 2 + 1:] + list(range(1, n + 1))[:n // 2 + 1]
	for i in range(n):
		print(*row[i:] + row[:i])


for _ in range(int(input())):
	k = eval(input())
	for i in range(k):
		for j in range(k):
			print((i + j + (k + 1) // 2) % k + 1, ' ', end='')
		print()


for _ in range(int(input())):
	k = int(input())
	if k == 1:
		print(1)
	else:
		for j in range(k):
			for i in range(1, k + 1):
				h = (i + j + k - k // 2) % k
				if h == 0:
					print(k, end=' ')
				else:
					print(h, end=' ')
			print()


t = int(input())
for _t in range(t):
	k = int(input())
	mid = k // 2 + 1
	for i in range(1, k + 1):
		j = mid + i
		for c in range(k):
			print(k if j % k == 0 else j % k, end=' ')
			j += 1
		print()


for m in range(int(input())):
	k = int(input())
	if k == 1:
		print(k)
		continue
	temp = k - k // 2
	for i in range(k):
		temp += 1
		for j in range(k):
			print(temp, end=' ')
			if j != k - 1 and temp == 1:
				temp = k
			else:
				temp -= 1
		print()


t = int(input())
for i in range(t):
	x = int(input())
	d = list(map(str, list(range(1, x + 1)) + list(range(1, x + 1)) + list(range(1, x + 1))))
	c = (x + 1) // 2
	f = x - 1
	g = c - 1
	for i in range(x, 0, -1):
		print(' '.join(d[g + i:c + f + i]))


T = int(input())
for _ in range(T):
	K = int(input())
	if K == 1:
		print(1)
		continue
	x = K // 2 + 2
	for r in range(K):
		for c in range(K):
			if c == K - 1:
				print(x)
			else:
				print(x, end=' ')
			x = x + 1
			if x > K:
				x = 1
		x = x + 1
		if x > K:
			x = 1


from collections import deque
for t in range(int(input())):
	k = int(input())
	arr = [x for x in range(1, k + 1)]
	d = deque(arr)
	e = ''
	s = ''
	for i in range(k):
		for j in range(k):
			if i < k / 2:
				e += str(d[j]) + ' '
			else:
				s += str(d[j]) + ' '
		if i < k / 2:
			e = e.strip() + '\n'
		else:
			s = s.strip() + '\n'
		d.appendleft(d.pop())
	print(s.strip())
	print(e.strip())


t = int(input())
for i in range(t):
	n = int(input())
	if n == 1:
		print('1 ')
	elif n == 3:
		print('3 2 1\n1 3 2\n2 1 3')
	else:
		fk = n // 2
		m = fk
		for j in range(n):
			var = n - m + 1
			for k in range(n):
				if k == m:
					print('1 ', end='')
					var = 2
					continue
				print(str(var) + ' ', end='')
				var += 1
			if m == 0:
				m = n - 2
			elif j == n - 2:
				m = n - 1
			else:
				m -= 1
			print()


t = int(input())
ans = []
for i in range(t):
	k = int(input())
	string = []
	temp_ans = ''
	for j in range(k):
		string.append(str(j + 1))
	if k == 1:
		ans.append('1')
	else:
		n = k // 2
		for j in range(n, -1, -1):
			temp_ans += ' '.join(string[j:]) + ' ' + ' '.join(string[0:j]) + '\n'
		for j in range(len(string) - 1, n, -1):
			if j == n + 1:
				temp_ans += ' '.join(string[j:]) + ' ' + ' '.join(string[0:j])
			else:
				temp_ans += ' '.join(string[j:]) + ' ' + ' '.join(string[0:j]) + '\n'
		ans.append(temp_ans)
for x in ans:
	print(x)


t = int(input())
while t:
	n = int(input())
	array = [x for x in range(1, n + 1)]
	for i in range(-(n - 1) // 2, (n - 1) // 2 + 1):
		for j in range(0, n):
			print(array[(i + j) % n], end=' ')
		print()
	t -= 1


def soln(n):
	mid = (n + 1) // 2
	for i in range(n):
		s = ''
		temp = mid
		for j in range(n):
			s += str(temp) + ' '
			temp += 1
			if temp > n:
				temp = 1
		mid -= 1
		if mid < 1:
			mid = n
		print(s)

def main():
	for _ in range(int(input())):
		n = int(input())
		soln(n)
main()


t = int(input())
for ii in range(0, t):
	n = int(input())
	if n == 1:
		print('1')
	else:
		origin = (n + 1) / 2 - 1
		for i in range(0, n):
			for j in range(0, n):
				tem = (j + i) % n + 1
				if tem == 1:
					print(int(origin), end=' ')
				elif tem == origin:
					print('1', end=' ')
				else:
					print(int(tem), end=' ')
			print()


import math
t = int(input())
while t:
	n = int(input())
	c = int((n + 1) / 2)
	for i in range(0, n):
		a = [0 for k in range(0, n)]
		for j in range(0, n):
			c += 1
			a[j] = str(int(math.fmod(c - i, n)))
			if a[j] == '0':
				a[j] = str(n)
		print(' '.join(a))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	x = (n + 1) // 2
	for i in range(n):
		for j in range(n):
			print((x + j + i) % n + 1, end=' ')
		print()


t = int(input())
while t:
	k = int(input())
	start = (k + 1) // 2
	for i in range(k):
		for j in range(k):
			print((start + j) % k + 1, end=' ')
		print()
		start += 1
	t -= 1


from math import ceil
t = int(input())
while t:
	t -= 1
	k = int(input())
	if k == 1:
		print(1)
		continue
	temp = 0
	finalList = []
	for i in range(2, ceil(k / 2) + 1):
		finalList.append(i)
		temp = i
	finalList.append(1)
	for i in range(temp + 1, k + 1):
		finalList.append(i)
	for i in finalList:
		print(i, end=' ')
	print()
	for i in range(k - 1):
		tmp = finalList.pop(0)
		finalList.append(tmp)
		for i in finalList:
			print(i, end=' ')
		print()


t = int(input().strip())

def per(a, k):
	c = a[0]
	for i in range(0, k - 1):
		a[i] = a[i + 1]
	a[k - 1] = c
for i in range(0, t):
	k = int(input().strip())
	a = list(range(1, k + 1))
	a.reverse()
	fk = (k - 1) // 2
	for j in range(0, fk + 1):
		per(a, k)
	for l in range(0, k):
		print(*a, end='')
		print('')
		per(a, k)


from collections import deque
t = int(input())
while t > 0:
	d = deque()
	k = int(input())
	limit = k // 2
	climit = limit
	j = 2
	while limit > 0:
		d.append(j)
		j = j + 1
		limit = limit - 1
	d.append(1)
	while climit > 0:
		d.append(j)
		j = j + 1
		climit = climit - 1
	while k > 0:
		for item in d:
			print(str(item) + ' ', end='')
		d.rotate(-1)
		k = k - 1
		print()
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	mid = n // 2 + 1
	count = 0
	for i in range(n):
		for j in range(1, n + 1):
			n1 = (j + mid + count) % n
			if n1 == 0:
				n1 = n
			print(n1, end=' ')
		print('')
		count += 1


def print_line(A):
	for i in A:
		print(i, end=' ')
	print()
t = int(input())
for _ in range(t):
	k = int(input())
	x = int((k + 3) / 2)
	A = list(range(x, k + 1)) + list(range(1, x))
	for i in range(k):
		print_line(A)
		A = A[1:] + A[:1]


t = int(input())
while t:
	k = int(input())
	m = n = k
	st = k // 2 + 2
	i = st
	cnt = 0
	if k == 1:
		print(1)
	else:
		while m:
			while cnt < k and i:
				print(i, end=' ')
				i += 1
				cnt += 1
				if i > k:
					i = 1
			m -= 1
			cnt = 0
			st += 1
			if st > k:
				i = st = 1
			else:
				i = st
			if m != 0:
				print()
	t -= 1
	if t != 0:
		print()


t = int(input())
while t > 0:
	k = int(input())
	li = [0] * k
	if k % 2 == 0:
		mid = k // 2 - 1
	else:
		mid = (k + 1) // 2 - 1
	p = 1
	for i in range(mid, mid + k):
		li[i % k] = p
		p = p + 1
	for i in range(k):
		for j in range(k):
			print(li[j], end=' ')
		print()
		k1 = li.pop()
		li.insert(0, k1)
	t = t - 1


def rotate(l, r):
	res = [0] * k
	for i in range(k):
		res[(i + r) % k] = l[i]
	return res
for i in range(int(input())):
	k = int(input())
	centre = (k + 1) // 2
	c = centre - 1
	j = k - 1
	ans = list()
	l1 = list(range(1, k + 1))
	while j >= 0:
		ans.append(rotate(l1, c))
		if c == 0:
			c = k
		c -= 1
		j -= 1
	for lis in ans:
		for num in lis:
			print(num, end=' ')
		print()


def main():
	from sys import stdin, stdout
	for _ in range(int(stdin.readline())):
		n = int(stdin.readline())
		l = []
		i = 0
		j = 2
		while i < n - 1:
			if j > n:
				j = n - 2
			l.append(n - j)
			if j & 1:
				j -= 2
			else:
				j += 2
			i += 1
		l += [n] + l
		for i in range(n):
			for j in range(n):
				stdout.write(str(l[i + j]) + ' ')
			stdout.write('\n')
main()


T = int(input())
for t in range(T):
	n = int(input())
	for i in range(n):
		print(' '.join([str((i + k + n // 2 + 1) % n + 1) for k in range(n)]))


test = int(input(''))
while test:
	n = int(input(''))
	ok = 1
	if n == 1:
		print(1)
		ok = 0
	jam = int((n + 1) / 2 + 1)
	for i in range(0, int((n + 1) / 2)):
		kak = jam
		for k in range(0, n):
			if kak > n:
				kak = kak % n
			if ok == 1:
				print(kak, end=' ')
			kak = kak + 1
		if ok == 1:
			print()
		jam = jam + 1
	jam = int(2)
	for i in range(0, int((n + 1) / 2) - 1):
		kak = jam
		for k in range(0, n):
			if kak > n:
				kak = kak % n
			if ok == 1:
				print(kak, end=' ')
			kak = kak + 1
		if ok == 1:
			print()
		jam = jam + 1
	test = test - 1


import numpy as np
grid = np.zeros((500, 500), dtype=np.int64)
t = int(input())
while t != 0:
	n = int(input())
	(x, y) = (n + 1, n)
	j = n // 2
	for i in range(n):
		if j == n:
			j = 0
		index = 0
		for a in range(x, n + 1):
			grid[j][index] = a
			index += 1
		for b in range(1, y + 1):
			grid[j][index] = b
			index += 1
		j += 1
		x -= 1
		y -= 1
	for i in range(n):
		for j in range(n):
			print(grid[i][j], end=' ')
		print('\n')
	t = t - 1


for i in range(int(input())):
	n = int(input())
	if n == 1:
		print(1)
	elif n % 2 == 1:
		(c, a, z, d) = ([], [], [], [])
		for i in range(n, 0, -1):
			c.append(i)
			z.append(i)
		a.append(z)
		d.append(c)
		for j in range(n - 1):
			m = []
			for k in range(n):
				m.append(a[j][(k + 1) % n])
			d.append(m)
			a.append(m)
		for x in range(n // 2, -1, -1):
			print(*d[x], sep=' ')
		for y in range(n - 1, n // 2, -1):
			print(*d[y], sep=' ')
	else:
		continue


t = int(input())
for v in range(t):
	k = int(input())
	f = k / 2
	l = [[0 for x in range(k)] for y in range(k)]
	z = int((k + 1) / 2)
	c = 0
	col = z - 2
	for j in range(k):
		c = c + 1
		if col != k - 1:
			col = col + 1
		else:
			col = 0
		for i in range(k):
			l[i][col] = c
			if col != k - 1:
				col = col + 1
			else:
				col = 0
	if k == 3:
		l = [[3, 1, 2], [2, 3, 1], [1, 2, 3]]
	for i in range(len(l)):
		for j in range(len(l)):
			print(l[i][j], end=' ')
		print()


import sys
sys.setrecursionlimit(50000000)

def read(var_type=int):
	n = var_type(input())
	return n

def read_array(var_type=int):
	arr = list((var_type(n) for n in input().split()))
	return arr
PRIME = 10 ** 9 + 7

def gcd(a, b):
	if b == 0:
		return a
	return b if a % b == 0 else gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def fill(A, n, x, row):
	for k in range(n):
		i = (row + k) % n
		j = k % n
		A[i][j] = x
t = read()
for i in range(t):
	n = read()
	A = [[0 for j in range(n)] for i in range(n)]
	row = n // 2
	for i in range(n):
		fill(A, n, i + 1, (row + i) % n)
	for i in range(n):
		for j in range(n):
			print(A[i][j], end=' ')
		print()


def alist(a):
	k = ''
	for i in a:
		k += str(i) + ' '
	return k

def shift(a, s):
	b = a[:]
	n = len(b)
	for i in range(n):
		b[(i + s) % n] = a[i]
	return b
for _ in range(int(input())):
	d = {}
	n = int(input())
	d[n // 2] = alist(range(1, n + 1))
	k = 1
	for i in range(n // 2 - 1, -1, -1):
		d[i] = alist(shift(list(range(1, n + 1)), k))
		k += 1
	k = 1
	for i in range(n // 2 + 1, n):
		d[i] = alist(shift(list(range(1, n + 1)), -k))
		k += 1
	for i in range(n):
		print(d[i])


t = int(input())
for i in range(t):
	k = int(input())
	a = list(range(1, k + 1))
	i = (k - 1) // 2
	for l in range(k):
		for j in range(k):
			print(a[i - j], end=' ')
		i += 1
		i = i % k
		print()


from itertools import cycle
T = int(input())
for i in range(T):
	K = int(input())
	if K == 1:
		print(1)
	mid = (K + 1) / 2
	A = []
	for j in range(1, K + 1):
		if j == 1:
			continue
		if j == mid + 1:
			A.append(1)
			A.append(j)
		else:
			A.append(j)
	pool = cycle(A)
	k = 0
	hj = 0
	while hj < K:
		ctr = 0
		i = k
		pool = cycle(A)
		for item in pool:
			if ctr == K:
				break
			if i >= 0:
				print(item, end=' ')
				ctr += 1
			i += 1
		print()
		k -= 1
		hj += 1


for t in range(int(input())):
	N = int(input())
	print(''.join((str(j % N + 1) + ('\n' if j == N + i - 1 else ' ') for i in range((N + 1) // 2, N + (N + 1) // 2) for j in range(i, N + i))), end='')


t = int(input())
while t is not 0:
	t -= 1
	k = int(input())
	d = (k + 1) / 2
	for i in range(k):
		s = (i + d) % k
		for j in range(k):
			print(int((s + j) % k + 1), end=' ')
		print()


for i in range(int(input())):
	c = int(input())
	p = c - c // 2
	r = c - c // 2 - 1
	for j in range(c // 2):
		for k in range(1, c + 1):
			if p > c:
				p = 1
			if p < 1:
				p = c
			print(p, end=' ')
			p = p + 1
		p = r
		r = r - 1
		print()
	q = 1
	m = c
	for j in range(c // 2 + 1):
		for k in range(1, c + 1):
			if q > c:
				q = 1
			print(q, end=' ')
			q = q + 1
		q = m
		m = m - 1
		print()


t = int(input())
for x in range(0, t):
	n = int(input())
	l = [x for x in range(1, n + 1)]
	ref = [x for x in range(-n // 2 + 2, 1, 1)]
	ref.extend([x for x in range(-n + 1, -n // 2 + 1, 1)])
	ref.append(-n // 2 + 1)
	for x in ref:
		for y in range(0, n):
			print(l[y + x], end=' ')
		print('')


for t in range(int(input())):
	N = int(input())
	for i in range((N + 1) // 2, N + (N + 1) // 2):
		print(' '.join((str(j % N + 1) for j in range(i, N + i))))


t = int(input())
for i in range(t):
	k = int(input())
	n = int(k / 2) + 1
	for j in range(k):
		m = n
		for l in range(k):
			print(n, end=' ')
			n = (n - 1) % k
			if n == 0:
				n = k
		n = (m - 1) % k
		if n == 0:
			n = k
		print()


def func1():
	i = int(input())
	ii = i // 2 + 1
	l = list(map(str, range(ii, 0, -1))) + list(map(str, range(i, ii, -1)))
	ll = []
	for _ in range(i):
		ll.append(' '.join(l))
		l = [l[-1]] + l[:-1]
	return ll
t = int(input())
ans = []
for _ in range(t):
	ans.append(func1())
for a in ans:
	for aa in a:
		print(aa)


T = int(input())
for _ in range(T):
	n = int(input())
	i = (1 + n) // 2
	a = [1 + i for i in range(n)]
	for j in range(n):
		for k in range(i, n):
			print(a[k], end=' ')
		for k in range(i):
			print(a[k], end=' ')
		print()
		i = (i + 1) % n


for _ in range(int(input())):
	k = int(input())
	if k == 1:
		print(1)
	elif k == 3:
		print('3 2 1')
		print('1 3 2')
		print('2 1 3')
	elif k == 5:
		print('5 4 3 2 1')
		print('3 5 4 1 2')
		print('1 3 2 4 5')
		print('2 1 5 3 4')
		print('4 2 1 5 3')
	else:
		a = []
		for _ in range(k):
			b = []
			for _ in range(k):
				b.append(0)
			a.append(b)
		mid = k // 2
		for j in range(k):
			for i in range(k):
				a[(mid + i) % k][j] = i + 1
			mid += 1
		for i in a:
			for j in i:
				print(j, end=' ')
			print('')


for t in range(int(input())):
	n = int(input())
	if n == 1:
		print(1)
		continue
	for i in range(1, n + 1):
		m = (n + 1) // 2 + i
		if m > n:
			m %= n
		for j in range(1, n + 1):
			print(m, end=' ')
			if m == n:
				m = 1
			else:
				m += 1
		print()


for _ in range(int(input())):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	for i in range(n):
		print(' '.join([str(i) for i in [arr[(arr[-n // 2] + j - i) % n] for j in range(n)]]))


def shift(k, l):
	return l[-k:] + l[:-k]
t = int(input())
for i in range(0, t):
	k = int(input())
	l = list(range(1, k + 1))
	for j in range((k + 1) // 2, (3 * k + 1) // 2):
		lt = list(shift(j % k, l))
		print(*lt)


def retsqr(n):
	A = list(range(n))
	A = [a + 1 for a in A]
	start = (n + 1) // 2
	for i in range(n):
		index = start
		s = ''
		for j in range(n):
			s += str(A[index % n])
			s += ' '
			index += 1
		start += 1
		print(s[:-1])
for tests in range(int(input())):
	N = int(input())
	retsqr(N)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 1:
		print(1)
	else:
		pat = [0] * n
		c = 1
		q = 1
		for i in range(n):
			pat[i] = c
			c += q * 2
			if c > n:
				c = n - 1
				q = -1
		q = (n + 1) // 2
		for i in range(n):
			m = q
			p = 1
			while p < n:
				print(pat[m], end=' ')
				m = (m + 1) % n
				p += 1
			print(pat[m])
			q = (q + 1) % n