Given an integer N, you need to print the following pattern.
Example 1:
Input:
N = 3
Output:
33333
32223
32123
32223
33333
Explanation:
When N = 3 then there will be three boundaries.
Outer boundary contains only 3.
Middle boundary contains only 2.
And the inner boundary contains only 1.
Example 2:
Input:
N = 4
Output:
4444444
4333334
4322234
4321234
4322234
4333334
4444444
Your Task:  
You don't need to read input. Your task is to complete the function printPattern() which takes an integer N as an input parameter and print the pattern for it.
Expected Time Complexity: O(N^{2})
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 9

Difficulty: EASY
Expected Time Complexity: O(N^{2})
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3
class Solution:
	def printPattern(self, N):
		# code here

Solutions:
class Solution:

	def printPattern(self, N):
		l = []
		for i in range(N, 0, -1):
			s = '' + str(N)
			k = N
			for j in range(0, N - i):
				k = k - 1
				s = s + str(k)
			s = s + (i - 1) * str(k)
			r = s[::-1]
			s = s + r[1:]
			l.append(s)
		l = l + l[::-1][1:]
		for i in l:
			print(i)


class Solution:

	def printPattern(self, N):
		for i in range(1, 2 * N):
			for j in range(1, 2 * N):
				print(max(abs(N - i), abs(N - j)) + 1, end='')
			print()


class Solution:

	def printPattern(self, n):
		size = 2 * n - 1
		front = 0
		back = size - 1
		a = [[0 for i in range(100)] for i in range(100)]
		while n != 0:
			for i in range(front, back + 1):
				for j in range(front, back + 1):
					if i == front or i == back or j == front or (j == back):
						a[i][j] = n
			front += 1
			back -= 1
			n -= 1
		for i in range(size):
			for j in range(size):
				print(a[i][j], end='')
			print()


class Solution:

	def printPattern(self, N):
		u = d = l = r = 0
		s1 = ''
		for i in range(1, 2 * N):
			s = ''
			for j in range(1, 2 * N):
				l = j - 1
				r = 2 * N - j - 1
				u = i - 1
				d = 2 * N - i - 1
				print(N - min(l, r, u, d), end='')
			print()


class Solution:

	def printPattern(self, N):
		for i in range(2 * N - 1):
			for j in range(2 * N - 1):
				k = min(i - 0, 2 * N - 2 - i)
				k1 = min(j - 0, 2 * N - 2 - j)
				print(N - min(k, k1), end='')
			print()


class Solution:

	def printPattern(self, N):
		top = 0
		left = 0
		right = 2 * N - 2
		down = 2 * N - 2
		for i in range(2 * N - 1):
			for j in range(2 * N - 1):
				mini = min(i - left, right - i, j - top, down - j)
				print(N - mini, end='')
			print()


class Solution:

	def printPattern(self, N):
		rig = 2 * N - 2
		lef = 0
		top = 0
		down = 2 * N - 2
		for i in range(0, 2 * N - 1):
			for j in range(0, 2 * N - 1):
				m = min(min(i - top, down - i), min(j - lef, rig - j))
				print(N - m, end='')
			print()


class Solution:

	def printPattern(self, n):
		for i in range(2 * n - 1):
			s = ''
			for j in range(2 * n - 1):
				k = min(i, j, 2 * n - 2 - i, 2 * n - 2 - j)
				s += str(n - k)
			print(s)


class Solution:

	def printPattern(self, N):
		l = []
		for i in range(N * 2 - 1):
			l.append(N)
		for ele in l:
			print(ele, end='')
		print('\r')
		start = 1
		end = N * 2 - 3
		for i in range(N - 1):
			temp = l[start]
			for j in range(start, end + 1):
				l[j] = temp - 1
			for ele in l:
				print(ele, end='')
			print('\r')
			start += 1
			end -= 1
		start = N - 1
		end = N - 1
		for i in range(N - 1):
			temp = l[start]
			for j in range(start, end + 1):
				l[j] = temp + 1
			for ele in l:
				print(ele, end='')
			print('\r')
			start -= 1
			end += 1


class Solution:

	def printPattern(self, N):
		l = []
		for i in range(2 * N - 1):
			l.append(N)
		for i in l:
			print(i, end='')
		print()
		c = 1
		for i in range(N - 1):
			for j in range(c, 2 * N - c - 1):
				l[j] -= 1
			for j in l:
				print(j, end='')
			print()
			c += 1
		s = N - 1
		e = N - 1
		for i in range(N - 1):
			for j in range(s, e + 1):
				l[j] += 1
			for j in l:
				print(j, end='')
			print()
			s -= 1
			e += 1


class Solution:

	def printPattern(self, N):
		for row in range(2 * N - 1):
			for col in range(2 * N - 1):
				top = row
				left = col
				right = 2 * N - 2 - col
				bottom = 2 * N - 2 - row
				print(N - min(min(top, bottom), min(left, right)), end='')
			print()


class Solution:

	def printPattern(self, N):
		for i in range(N, 0, -1):
			for j in range(N, 0, -1):
				if j > i:
					print(j, end='')
				else:
					print(i, end='')
			for j in range(2, N + 1):
				if j > i:
					print(j, end='')
				else:
					print(i, end='')
			print()
		for i in range(2, N + 1):
			for j in range(N, 0, -1):
				if j > i:
					print(j, end='')
				else:
					print(i, end='')
			for j in range(2, N + 1):
				if j > i:
					print(j, end='')
				else:
					print(i, end='')
			print()


class Solution:

	def printPattern(self, N):
		arr = [[1 for j in range(2 * N - 1)] for i in range(2 * N - 1)]
		low = 0
		high = 2 * N - 1
		num = N
		while low < high:
			for i in range(low, high):
				for j in range(low, high):
					arr[i][j] = num
			low += 1
			high -= 1
			num -= 1
		for i in range(2 * N - 1):
			for j in range(2 * N - 1):
				print(arr[i][j], end='')
			print()


class Solution:

	def printPattern(self, N):
		for i in range(1, 2 * N):
			temp = ''
			for j in range(1, 2 * N):
				temp += str(max(abs(N - i), abs(N - j)) + 1)
			print(temp)


class Solution:

	def printPattern(self, N):
		for i in range(1 - N, N):
			for j in range(1 - N, N):
				if abs(i) > abs(j):
					print(abs(i) + 1, end='')
				else:
					print(abs(j) + 1, end='')
			print()


class Solution:

	def printPattern(self, N):
		x = (2 * N - 1) * str(N)
		l = [x]
		d = N - 1
		s = 2 * N - 1
		for i in range(1, N):
			y = l[-1][:i] + (s - 2 * i) * str(d) + l[-1][s - i:]
			l.append(y)
			d = d - 1
		m = len(l)
		for i in l:
			print(i)
		for i in range(m - 2, -1, -1):
			print(l[i])


class Solution:

	def printPattern(self, N):
		f = 1
		r = 0
		while r > -1:
			for c in range(0, N * 2 - 1):
				if r > c:
					print(N - c, end='')
				elif c < (N - r) * 2 - 1 + r:
					print(N - r, end='')
				else:
					print(N - r + c - ((N - r) * 2 - 1 + r) + 1, end='')
			print()
			if r == N - 1:
				f = -1
			r += f


class Solution:

	def printPattern(self, N):
		e = (2 * N - 1) * str(N)
		l = [e]
		d = N - 1
		g = 2 * N - 1
		for i in range(1, N):
			t = l[-1][:i] + (g - 2 * i) * str(d) + l[-1][g - i:]
			l.append(t)
			d = d - 1
		c = len(l)
		for i in l:
			print(i)
		for i in range(c - 2, -1, -1):
			print(l[i])


class Solution:

	def printPattern(self, N):
		x = [N + 1] * N
		for i in range(N):
			for j in reversed(range(0, N - i)):
				x[j] = x[j] - 1
			print(*x[::-1], sep='', end='')
			print(*x[1:], sep='')
		for i in reversed(range(1, N)):
			for j in reversed(range(0, N - i)):
				x[j] = x[j] + 1
			print(*x[::-1], sep='', end='')
			print(*x[1:], sep='')


class Solution:

	def printPattern(self, N):
		for i in range(1, 2 * N):
			for j in range(1, 2 * N):
				print(max(abs(N - i), abs(N - j)) + 1, end='')
			print()
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		N = int(input())
		ob = Solution()
		ob.printPattern(N)


class Solution:

	def printPattern(self, N):
		ans = [[N for i in range(2 * N - 1)]]
		edge = 1
		while len(ans) < N:
			lastList = list(ans[-1])
			for i in range(edge, len(lastList) - edge):
				lastList[i] -= 1
			ans.append(lastList)
			edge += 1
		otherHalf = ans[:len(ans) - 1]
		ans.extend(otherHalf[::-1])
		for i in range(len(ans)):
			for j in range(len(ans[i])):
				print(ans[i][j], end='')
			print()
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		N = int(input())
		ob = Solution()
		ob.printPattern(N)


class Solution:

	def printPattern(self, N):
		total_chars = 2 * N - 1
		top_row = []
		for _ in range(total_chars):
			top_row.append(N)
		all_rows = [top_row]
		for i in range(1, N):
			new_row = all_rows[-1].copy()
			for j in range(i, N):
				new_row[j] -= 1
			row_mirror = new_row[:N - 1]
			row_mirror.reverse()
			new_row[N:] = row_mirror
			all_rows.append(new_row)
		column_mirror = all_rows[:N - 1]
		column_mirror.reverse()
		all_rows.extend(column_mirror)
		for row in all_rows:
			print(''.join([str(i) for i in row]))
		return


class Solution:

	def printPattern(self, N):
		nn = 2 * N - 1
		a = [[0] * nn] * nn
		for i in range(0, nn):
			for j in range(0, nn):
				x = nn - i - 1
				y = nn - j - 1
				m = max(abs(N - i), abs(N - j), abs(N - x), abs(N - y))
				print(m, end='')
			print()


class Solution:

	def printPattern(self, N):
		n = 2 * N - 1
		a = []
		for i in range(n):
			a.append([0] * n)
		for i in range(n):
			for j in range(n):
				k = min([n - 1 - i, n - 1 - j, i, j])
				a[i][j] = N - k
				print(a[i][j], end='')
			print()


class Solution:

	def printPattern(self, N):
		n = str(N) * (2 * N - 1)
		n = int(n)
		p = str(1)
		p = p * (2 * N - 1)
		p = list(p.strip(''))
		k = 1
		g = [n]
		temp = n
		for i in range(N - 1):
			p[i] = '0'
			p[len(p) - i - 1] = '0'
			temp = temp - int(''.join(p))
			g.append(temp)
		for i in g:
			print(i)
		for i in range(N - 1):
			print(g[N - (2 + i)])


class Solution:

	def printPattern(self, N):
		n = N
		arr = ['0' for x in range(2 * n - 1)]
		temp = []
		for x in range(n):
			a = 2 * n - 1 - x
			arr[x:2 * n - 1 - x] = [str(n - x)] * (a - x)
			print(''.join(arr))
			temp.append(arr.copy())
		for x in reversed(temp[:-1]):
			print(''.join(x))


class Solution:

	def printPattern(self, N):
		for i in range(1, N + 1):
			k = N
			for j in range(1, i + 1):
				print(k, end='')
				k -= 1
			for j in range(i + 1, 2 * N - i + 1):
				print(N - i + 1, end='')
			k = N - i + 2
			for j in range(2 * N - i + 1, 2 * N):
				print(k, end='')
				k += 1
			print()
		for i in range(1, N):
			k = N
			for j in range(1, N - i + 1):
				print(k, end='')
				k = k - 1
			for j in range(N - i + 1, N + i + 1):
				print(i + 1, end='')
			k = i + 2
			for j in range(N + i + 1, 2 * N):
				print(k, end='')
				k = k + 1
			print()


class Solution:

	def printPattern(self, N):
		pattern = str(N) * (2 * N - 1)
		for k in range(1, N):
			print(pattern)
			pattern = pattern[0:k] + str(N - k) * (len(pattern) - 2 * k) + pattern[len(pattern) - k:]
		for k in range(2, N + 1):
			print(pattern)
			pattern = pattern[0:N - k] + str(k) * (2 * k - 1) + pattern[len(pattern) - (N - k):]
		print(pattern)


class Solution:

	def printPattern(self, n):
		s = 0
		l = 2 * n - 1
		a = [[0 for i in range(l)] for i in range(l)]
		e = l
		while n != 0:
			for i in range(s, e):
				for j in range(s, e):
					if i in (s, e - 1) or j in (s, e - 1):
						a[i][j] = n
			e -= 1
			s += 1
			n -= 1
		for i in range(l):
			for j in range(l):
				print(a[i][j], end='')
			print()


class Solution:

	def printPattern(self, N):
		curr = [N for i in range(2 * N - 1)]
		pattern = [[x for x in curr]]
		start = 1
		count = 2 * (N - 1) - 1
		val = N - 1
		for i in range(N - 1):
			for j in range(start, start + count):
				curr[j] = val
			pattern.append([x for x in curr])
			start += 1
			val -= 1
			count = 2 * val - 1
		for row in pattern:
			for i in row:
				print(i, end='')
			print()
		for row in pattern[::-1][1:]:
			for i in row:
				print(i, end='')
			print()


class Solution:

	def printPattern(self, N):
		arr = []
		for i in range(2 * N - 1):
			arr.append(N)
		i = 0
		j = 2 * N - 2
		while i <= j:
			i2 = i
			j2 = j
			for k in range(i2, j2 + 1):
				arr[i2] = arr[j2] = N
				i2 += 1
				j2 -= 1
			i += 1
			j -= 1
			N -= 1
			ans = ''
			for z in arr:
				ans += str(z)
			print(ans)
		N += 2
		i -= 1
		j += 1
		while i >= 1 and j < len(arr) - 1:
			i3 = i
			j3 = j
			var = abs(i3 - (j3 + 1))
			for l in range(var):
				try:
					arr[i3] = arr[j3] = N
				except:
					print(i3, j3, var)
				i3 += 1
				j3 -= 1
			i -= 1
			j += 1
			N += 1
			ans2 = ''
			for x in arr:
				ans2 += str(x)
			print(ans2)


class Solution:

	def printPattern(self, N):
		arr = [str(N)] * (2 * N - 1)
		print(''.join(arr))
		for i in range(1, N):
			arr1 = arr[i:2 * N - 1 - i]
			l = len(arr1)
			arr[i:2 * N - 1 - i] = [str(N - i)] * l
			print(''.join(arr))
		for i in range(N - 2, -1, -1):
			arr1 = arr[i:2 * N - 1 - i]
			l = len(arr1)
			arr[i:2 * N - 1 - i] = [str(N - i)] * l
			print(''.join(arr))


class Solution:

	def printPattern(self, N):
		for i in range(N, 0, -1):
			sum = 0
			num = N
			count = 1
			for j in range(-N + 1, N):
				sum = i + j
				if sum < 1:
					num = abs(j) + 1
					print(num, end='')
					num -= 1
				elif count < 2 * i:
					print(num, end='')
					count += 1
				else:
					print(num + 1, end='')
					num += 1
			print()
		if N != 1:
			for i in range(2, N + 1):
				sum = 0
				num = N
				count = 1
				for j in range(-N + 1, N):
					sum = i + j
					if sum < 1:
						num = abs(j) + 1
						print(num, end='')
						num -= 1
					elif count < 2 * i:
						print(num, end='')
						count += 1
					else:
						print(num + 1, end='')
						num += 1
				print()


class Solution:

	def printPattern(self, N):
		length = N * 2 - 1
		index = 2
		strarr = ''
		for i in range(0, length):
			arr = []
			strarr = ''
			if N > i:
				k = N - i
			else:
				k = index
				index += 1
			for j in range(N, k, -1):
				strarr += str(j)
			for l in range(0, k * 2 - 1):
				strarr += str(k)
			for j in range(k + 1, N + 1):
				strarr += str(j)
			print(strarr)


class Solution:
	m = lambda self, a, b: a if a > b else b

	def printPattern(self, N):
		for i in range(N, 0, -1):
			for j in range(N, 0, -1):
				print(self.m(i, j), end='')
			for j in range(2, N + 1):
				print(self.m(i, j), end='')
			print()
		for i in range(2, N + 1):
			for j in range(N, 0, -1):
				print(self.m(i, j), end='')
			for j in range(2, N + 1):
				print(self.m(i, j), end='')
			print()