Given a number N, identify the pattern from  the given Examples and print the Output.
 
Example 1:
Input:
N = 4
Output:
ABCD
E$$F
G$$H
IJKL
Example 2:
Input:
N = 6
Output:
ABCDEF
G$$$$H
I$$$$J
K$$$$L
M$$$$N
OPQRST
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function findThePattern() which takes an Integer N as input and returns a vector of strings where each line represents lines of the pattern. For example, if N = 4, the vector v = {"ABCD", "E$$F", "G$$H", "IJKL"}.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
 
Constraints:
1 <= N <= 6

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3



class Solution:

    def findThePattern(self, N):

        # code here 

Solutions:
class Solution:

	def findThePattern(self, n):
		(ch, ls) = (0, [])
		for i in range(n):
			tmp = ''
			for j in range(n):
				if i == 0 or j == 0 or i == n - 1 or (j == n - 1):
					tmp += chr(ch + 65)
					ch += 1
				else:
					tmp += '$'
			ls.append(tmp)
		return ls


class Solution:

	def findThePattern(self, N):
		t = 65
		for i in range(N):
			for j in range(N):
				if i == 0 or i == N - 1 or j == 0 or (j == N - 1):
					print(chr(t), end='')
					t = t + 1
				else:
					print('$', end='')
			print()
		return []


class Solution:

	def findThePattern(self, N):
		t = []
		d = 65
		for i in range(0, N):
			s = ''
			if i == 0 or i == N - 1:
				for j in range(0, N):
					s = s + chr(d)
					d = d + 1
			else:
				for j in range(0, 2):
					s = s + chr(d)
					d = d + 1
				s = s[0] + '$' * (N - 2) + s[-1]
			t.append(s)
		return t


class Solution:

	def findThePattern(self, n):
		l = []
		x = 1
		for i in range(1, n + 1):
			s = ''
			for j in range(1, n + 1):
				if i == 1 or i == n or j == 1 or (j == n):
					s = s + chr(x + 64)
					x += 1
				else:
					s = s + '$'
			l.append(s)
		return l


class Solution:

	def findThePattern(self, N):
		lst = []
		a = ord('A')
		k = 0
		for i in range(N):
			s = ''
			for j in range(N):
				if i == 0 or i == N - 1 or j == 0 or (j == N - 1):
					s += chr(a + k)
					k += 1
				else:
					s += '$'
			lst.append(s)
		return lst


class Solution:

	def findThePattern(self, N):
		k = 65
		l = []
		s = ''
		for i in range(1, N + 1):
			for j in range(1, N + 1):
				if i == 1 or i == N or j == 1 or (j == N):
					s = s + chr(k)
					k = k + 1
				else:
					s = s + '$'
			l.append(s)
			s = ''
		return l


class Solution:

	def findThePattern(self, N):
		asci = 65
		ans = []
		for i in range(N):
			s = ''
			for j in range(N):
				if i == 0 or i == N - 1 or j == 0 or (j == N - 1):
					s += chr(asci)
					asci += 1
				else:
					s += '$'
			ans.append(s)
		return ans


class Solution:

	def findThePattern(self, N):
		a = 64
		c = 0
		s1 = []
		for i in range(1, N + 1):
			s = ''
			for j in range(1, N + 1):
				if i == 1 or i == N or j == 1 or (j == N):
					c += 1
					s += chr(a + c)
				else:
					s += '$'
			s1.append(s)
		return s1


class Solution:

	def findThePattern(self, n):
		a = []
		k = 0
		for i in range(n):
			x = ''
			for j in range(n):
				if i == 0 or i == n - 1 or j == 0 or (j == n - 1):
					x += chr(k + 65)
					k += 1
				else:
					x += '$'
			a.append(x)
		return a


class Solution:

	def findThePattern(self, N):
		c = 65
		l = []
		for i in range(N):
			s = ''
			for j in range(N):
				if i == 0 or i == N - 1:
					s += chr(c)
					c += 1
				elif j == 0 or j == N - 1:
					s += chr(c)
					c += 1
				else:
					s += '$'
			l.append(s)
		return l


class Solution:

	def findThePattern(self, n):
		c = 1
		for i in range(n):
			for j in range(n):
				if i == 0 or j == 0 or i == n - 1 or (j == n - 1):
					print(chr(65 + c - 1), end='')
					c += 1
				else:
					print('$', end='')
			print()
		return []


class Solution:

	def findThePattern(self, N):
		a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		i = 0
		x = ''
		ans = []
		j = 0
		while j < N:
			count = 0
			if j == 0 or j == N - 1:
				while count < N:
					x += a[i]
					i += 1
					count += 1
			else:
				while count < N:
					if count == 0 or count == N - 1:
						x += a[i]
						count += 1
						i += 1
					else:
						x += '$'
						count += 1
			ans.append(x)
			x = ''
			j += 1
		return ans


class Solution:

	def findThePattern(self, N):
		k = 0
		b = []
		if N == 1:
			b.append('A')
			return b
		for i in range(0, N):
			c = ''
			c = c + chr(65 + k)
			k += 1
			if i == 0 or i == N - 1:
				for j in range(0, N - 2):
					c = c + chr(65 + k)
					k += 1
			else:
				for l in range(0, N - 2):
					c = c + '$'
			c = c + chr(65 + k)
			k += 1
			b.append(c)
		return b


class Solution:

	def findThePattern(self, N):
		self.c = ''
		self.ch = 'A'
		self.m = []
		for i in range(1, N + 1):
			for j in range(1, N + 1):
				if i == 1 or j == 1 or i == N or (j == N):
					self.c += self.ch
					self.ch = chr(ord(self.ch) + 1)
				else:
					self.c += '$'
			self.m.append(self.c)
			self.c = ''
		return self.m


class Solution:

	def findThePattern(self, n):
		k = n * 2 + (n - 1) * 2
		a = []
		if n == 1:
			return 'A'
		p = 0
		s = ''
		for i in range(n):
			s += chr(p + 65)
			p += 1
		a.append(s)
		for i in range(n - 2):
			s = ''
			for j in range(n):
				if j == 0 or j == n - 1:
					s += chr(p + 65)
					p += 1
				else:
					s += '$'
			a.append(s)
		s = ''
		for i in range(n):
			s += chr(p + 65)
			p += 1
		a.append(s)
		return a


class Solution:

	def findThePattern(self, N):
		char = 65
		l = []
		for i in range(1, N + 1):
			temp = ''
			for j in range(1, N + 1):
				if i == 1 or i == N:
					temp += chr(char)
					char += 1
				elif j == 1:
					temp += chr(char)
				elif j == N:
					temp += chr(char + 1)
					char += 2
				else:
					temp += '$'
			l.append(temp)
		return l


class Solution:

	def findThePattern(self, N):
		import string
		letters = string.ascii_uppercase
		letters_iterator = iter(letters)
		strings = []
		for i in range(1, N + 1):
			if i == 1 or i == N:
				word = ''
				for _ in range(N):
					word += next(letters_iterator)
				strings.append(word)
			else:
				word = ''
				word += next(letters_iterator)
				for _ in range(N - 2):
					word += '$'
				word += next(letters_iterator)
				strings.append(word)
		return strings


class Solution:

	def findThePattern(self, N):
		k = ord('A')
		m = []
		for i in range(1, N + 1):
			if i == 1 or i == N:
				o = []
				for j in range(N):
					o.append(chr(k))
					k += 1
				m.append(''.join(o))
			else:
				l = []
				for j in range(N):
					if j == 0 or j == N - 1:
						l.append(chr(k))
						k += 1
					else:
						l.append('$')
				m.append(''.join(l))
		return m


class Solution:

	def findThePattern(self, N):
		x = 65
		ans = []
		for i in range(N):
			a = ''
			for j in range(N):
				if i == 0 or i == N - 1:
					a = a + chr(x)
					x = x + 1
				elif j == 0 or j == N - 1:
					a = a + chr(x)
					x = x + 1
				else:
					a = a + '$'
			ans.append(a)
		return ans


class Solution:

	def findThePattern(self, N):
		a = ord('A')
		l = []
		for i in range(N):
			k = ''
			for j in range(N):
				if i == 0:
					k += chr(a)
					a += 1
				elif i == N - 1:
					k += chr(a)
					a += 1
				elif j > 0 and j < N - 1:
					k += '$'
				else:
					k += chr(a)
					a += 1
			l.append(k)
		return l


class Solution:

	def findThePattern(self, N):
		if N == 1:
			return 'A'
		alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		arr = [0] * N
		arr[0] = alpha[0:N]
		last_ele = N + (N - 2) * 2
		arr[N - 1] = alpha[last_ele:last_ele + N]
		j = N
		for i in range(1, N - 1):
			arr[i] = alpha[j] + '$' * (N - 2) + alpha[j + 1]
			j += 2
		return arr


class Solution:

	def findThePattern(self, N):
		l = []
		x = ''
		ch = ord('A')
		k = 0
		for i in range(N):
			for j in range(N):
				if i == 0 or i == N - 1 or j == 0 or (j == N - 1):
					x += chr(ch + k)
					k += 1
				else:
					x += '$'
			l.append(x)
			x = ''
		return l


class Solution:

	def findThePattern(self, N):
		result_arr = []
		start = ord('A')
		current_symbol = ord('A')
		current_num = 1
		while current_num <= N:
			interm_string = ''
			for i in range(N):
				if i == 0 or i == N - 1:
					interm_string = interm_string + chr(current_symbol)
					current_symbol = current_symbol + 1
				elif current_num == 1 or current_num == N:
					interm_string = interm_string + chr(current_symbol)
					current_symbol = current_symbol + 1
				else:
					interm_string = interm_string + '$'
			result_arr.append(interm_string)
			current_num = current_num + 1
		return result_arr


class Solution:

	def findThePattern(self, N):
		num = N
		abc = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
		count = 0
		lis = []
		temp = ''
		for i in range(0, num):
			if i == 0 or i == num - 1:
				j = 0
				while j < num:
					temp = temp + abc[count]
					count += 1
					j += 1
				lis.append(temp)
				temp = ''
			else:
				j = 0
				while j < num:
					if j == 0 or j == num - 1:
						temp = temp + abc[count]
						count += 1
						j += 1
					else:
						temp = temp + '$'
						j += 1
				lis.append(temp)
				temp = ''
		return lis


class Solution:

	def findThePattern(self, N):
		flag = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		k = 0
		res = []
		str1 = ''
		for i in range(N):
			j = 0
			while j < N:
				if i > 0 and i < N - 1:
					if j > 0 and j < N - 1:
						str1 += '$'
						j += 1
						continue
					str1 += flag[k]
					j += 1
					k += 1
					continue
				str1 += flag[k]
				k += 1
				j += 1
			res.append(str1)
			str1 = ''
		return res


class Solution:

	def findThePattern(self, N):
		a = 65
		l = []
		w = ''
		for i in range(N):
			w += chr(a)
			a += 1
		l.append(w)
		for i in range(N - 2):
			w = ''
			w += chr(a)
			a += 1
			w += '$' * (N - 2)
			w += chr(a)
			a += 1
			l.append(w)
		w = ''
		if N > 1:
			for i in range(N):
				w += chr(a)
				a += 1
			l.append(w)
		return l


class Solution:

	def findThePattern(self, N):
		l = []
		x = 65
		for i in range(0, N):
			temp = ''
			for j in range(0, N):
				if i == 0 or i == N - 1 or j == 0 or (j == N - 1):
					temp = temp + chr(x)
					x += 1
				else:
					temp = temp + '$'
			l.append(temp)
		return l


class Solution:

	def findThePattern(self, N):
		t = ''
		d = 65
		l = []
		for i in range(N):
			t = ''
			for j in range(N):
				if i == 0 or i == N - 1 or j == 0 or (j == N - 1):
					t += chr(d)
					d += 1
				else:
					t += '$'
			l.append(t)
		return l
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ptr = ob.findThePattern(N)
		for i in ptr:
			print(i)


class Solution:

	def findThePattern(self, N):
		if N == 1:
			return ['A']
		if N == 2:
			return ['AB', 'CD']
		if N == 3:
			return ['ABC', 'D$E', 'FGH']
		if N == 4:
			return ['ABCD', 'E$$F', 'G$$H', 'IJKL']
		if N == 5:
			return ['ABCDE', 'F$$$G', 'H$$$I', 'J$$$K', 'LMNOP']
		if N == 6:
			return ['ABCDEF', 'G$$$$H', 'I$$$$J', 'K$$$$L', 'M$$$$N', 'OPQRST']
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ptr = ob.findThePattern(N)
		for i in ptr:
			print(i)


class Solution:

	def findThePattern(self, n):
		i = 0
		ans = []
		for j in range(n):
			string = ''
			if j == 0 or j == n - 1:
				for x in range(n):
					string += chr(i % 26 + 65)
					i += 1
			else:
				string += chr(i % 26 + 65)
				i += 1
				for x in range(n - 2):
					string += '$'
				string += chr(i % 26 + 65)
				i += 1
			ans.append(string)
		return ans
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ptr = ob.findThePattern(N)
		for i in ptr:
			print(i)


class Solution:

	def findThePattern(self, N):
		ans = []
		k = 0
		for i in range(N):
			if i == 0 or i == N - 1:
				p = ''
				for j in range(N):
					p += chr(65 + k)
					k += 1
				ans.append(p)
			else:
				p = ''
				p += chr(65 + k)
				k += 1
				for j in range(N - 2):
					p += '$'
				p += chr(65 + k)
				k += 1
				ans.append(p)
		return ans


class Solution:

	def findThePattern(self, N):
		s1 = []
		A = 65
		for i in range(N):
			s = ''
			for j in range(N):
				if i == 0 or i == N - 1:
					s += chr(A)
					A += 1
				elif j == 0 or j == N - 1:
					s += chr(A)
					A += 1
				else:
					s += '$'
			s1.append(s)
		return s1


class Solution:

	def findThePattern(self, N):
		alphat = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
		list = []
		pos = 0
		for i in range(1, N + 1):
			str = ''
			for j in range(N):
				if i == 1 or i == N or j == 0 or (j == N - 1):
					str = str + alphat[pos]
					pos = pos + 1
				else:
					str = str + '$'
			list.append(str)
		return list


class Solution:

	def findThePattern(self, N):
		result = []
		next_char = 65
		for i in range(N):
			word = ''
			if i in (0, N - 1):
				for j in range(N):
					word += chr(next_char)
					next_char += 1
			else:
				word += chr(next_char)
				next_char += 1
				word += '$' * (N - 2)
				word += chr(next_char)
				next_char += 1
			result.append(word)
		return result


class Solution:

	def findThePattern(self, N):
		res = []
		temp = 65
		for i in range(N):
			val = ''
			if i == 0 or i == N - 1:
				for j in range(N):
					val += chr(temp)
					temp += 1
			else:
				for j in range(N):
					if j > 0 and j < N - 1:
						val += '$'
					else:
						val += chr(temp)
						temp += 1
			res.append(val)
		return res


class Solution:

	def findThePattern(self, N):
		ch = 'A'
		a = []
		for i in range(N):
			t = ''
			for j in range(N):
				if i == 0 or j == 0 or i == N - 1 or (j == N - 1):
					t += ch
					ch = chr(ord(ch) + 1)
				else:
					t += '$'
			a.append(t)
		return a


class Solution:

	def findThePattern(self, N):
		ans = []
		ord_a = ord('A')
		for i in range(N):
			a = ''
			if i == 0 or i == N - 1:
				for j in range(N):
					a += chr(ord_a)
					ord_a += 1
			else:
				for j in range(N):
					if j == 0 or j == N - 1:
						a += chr(ord_a)
						ord_a += 1
					else:
						a += '$'
			ans.append(a)
		return ans


class Solution:

	def findThePattern(self, N):
		c = ord('A')
		k = 0
		for i in range(N):
			for j in range(N):
				if i == 0 or i == N - 1 or j == 0 or (j == N - 1):
					print(chr(c + k), end='')
					k += 1
				else:
					print('$', end='')
			print()
		return ''