You are given an 8\times 8 chessboard. Your enemy king is at point (X,Y) (1 ≤ X,Y ≤ 8).

You need to place some number of [queen] pieces on the chessboard such that the following conditions are satisfied:

The king should not be under attack by any of the queens that you have placed.
The [king] should not be able to make any move.

Note that a king can move one unit in any of the 8 direction while a queen can attack horizontally, vertically as well as diagonally.

Find the minimum number of queens required to satisfy the given conditions.
Print the chessboard where 0 denotes empty cells, 1 denotes the king, and 2 denotes the queen(s) placed by you in some position(s).

In case of multiple answers, print any.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- The only line of each test case contains two space-separated integers A and B — the coordinates of the king.
    
------ Output Format ------ 

For each test case, output a 8\times 8 grid consisting of King, Queen(s) and blank cells.

Print the chessboard in 8 lines where each line has 8 space-separated integers where 0 denotes empty cells, 1 denotes the king, and 2 denotes the queen(s) placed by you in some position(s).

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

$1 ≤ T ≤ 64$
$1 ≤ A,B ≤ 8$

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

----- Sample Output 1 ------ 
0 0 2 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 2 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
----- explanation 1 ------ 
Test case $1$: We can place $2$ queens at $(1, 3)$ and $(3, 3)$ respectively. Thus, the king at $(2, 1)$ has no safe squares to go to and is not under attack. 

![image]

Difficulty: MEDIUM_HARD

Solutions:
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	ans = [[0 for _ in range(8)] for _ in range(8)]
	ans[x][y] = 1
	a = [[0, 0], [0, 7], [7, 0], [7, 7]]
	b = [[-2, -1], [-2, +1], [-1, -2], [-1, +2], [+1, -2], [+1, +2], [+2, -1], [+2, +1]]
	if [x, y] in a:
		for i in range(len(b)):
			if 0 <= x + b[i][0] <= 7 and 0 <= y + b[i][1] <= 7:
				ans[x + b[i][0]][y + b[i][1]] = 2
				break
	elif x == 0:
		ans[x + 2][y - 1] = 2
		ans[x + 2][y + 1] = 2
	elif x == 7:
		ans[x - 2][y - 1] = 2
		ans[x - 2][y + 1] = 2
	elif y == 0:
		ans[x + 1][y + 2] = 2
		ans[x - 1][y + 2] = 2
	elif y == 7:
		ans[x + 1][y - 2] = 2
		ans[x - 1][y - 2] = 2
	elif x == 1 and y == 1:
		ans[x + 2][y - 1] = 2
		ans[x - 1][y + 3] = 2
	elif x == 1 and y == 6:
		ans[x - 1][y - 3] = 2
		ans[x + 2][y + 1] = 2
	elif x == 6 and y == 1:
		ans[x - 2][y - 1] = 2
		ans[x + 1][y + 3] = 2
	elif x == 6 and y == 6:
		ans[x - 2][y + 1] = 2
		ans[x + 1][y - 3] = 2
	elif y == 1 or y == 6:
		ans[x - 2][y + 1] = 2
		ans[x + 2][y - 1] = 2
	elif x == 1 or x == 6:
		ans[x - 1][y - 2] = 2
		ans[x + 1][y + 2] = 2
	else:
		ans[x - 1][y - 2] = 2
		ans[x + 1][y + 2] = 2
	for i in range(8):
		print(*ans[i])


T = int(input())
for t in range(T):
	(A, B) = map(int, input().split())
	(A, B) = (A - 1, B - 1)
	grid = [[0 for j in range(8)] for i in range(8)]
	grid[A][B] = 1
	if A in {0, 7} and B in {0, 7}:
		if A == 0 and B == 0:
			grid[1][2] = 2
		elif A == 0 and B == 7:
			grid[1][5] = 2
		elif A == 7 and B == 0:
			grid[6][2] = 2
		elif A == 7 and B == 7:
			grid[6][5] = 2
	elif A in range(1, 7) and B in {0, 7}:
		if B == 0:
			grid[A - 1][2] = 2
			grid[A + 1][2] = 2
		elif B == 7:
			grid[A - 1][5] = 2
			grid[A + 1][5] = 2
	elif A in {0, 7} and B in range(1, 7):
		if A == 0:
			grid[2][B - 1] = 2
			grid[2][B + 1] = 2
		elif A == 7:
			grid[5][B - 1] = 2
			grid[5][B + 1] = 2
	elif A in range(1, 5) and B in range(1, 6):
		grid[A - 1][B + 2] = 2
		grid[A + 3][B - 1] = 2
	elif A in range(1, 5) and B == 6:
		grid[A - 1][B - 2] = 2
		grid[A + 3][B + 1] = 2
	elif A == 5 and B in range(1, 7):
		grid[A - 2][B - 1] = 2
		grid[A + 2][B + 1] = 2
	elif A == 6 and B in range(1, 5):
		grid[A - 2][B - 1] = 2
		grid[A + 1][B + 3] = 2
	elif A == 6 and B in {5, 6}:
		grid[A - 3][B + 1] = 2
		grid[A + 1][B - 2] = 2
	for i in range(8):
		print(*grid[i])


def main():
	t = int(input())
	for i in range(t):
		(x, y) = tuple(map(int, input().split()))
		solve(x - 1, y - 1)

def solve(x, y):
	m = [[0] * 8 for i in range(8)]
	m[x][y] = 1
	if x in range(2, 6) and y in range(1, 7):
		m[x - 2][y - 1] = 2
		m[x + 2][y + 1] = 2
	elif x in range(1, 7) and y in range(2, 6):
		m[x - 1][y - 2] = 2
		m[x + 1][y + 2] = 2
	elif x in (0, 7):
		if y in (0, 7):
			u = x + 2 if x == 0 else x - 2
			v = y + 1 if y == 0 else y - 1
			m[u][v] = 2
		else:
			u = x + 2 if x == 0 else x - 2
			m[u][y - 1] = 2
			m[u][y + 1] = 2
	elif y in (0, 7):
		if x in (0, 7):
			u = x + 1 if x == 0 else x - 1
			v = y + 2 if y == 0 else y - 2
			m[u][v] = 2
		else:
			v = y + 2 if y == 0 else y - 2
			m[x - 1][v] = 2
			m[x + 1][v] = 2
	else:
		if (x, y) == (1, 1):
			m[3][0] = 2
			m[0][4] = 2
		if (x, y) == (6, 1):
			m[7][4] = 2
			m[4][0] = 2
		if (x, y) == (6, 6):
			m[4][7] = 2
			m[7][3] = 2
		if (x, y) == (1, 6):
			m[0][3] = 2
			m[3][7] = 2
	for row in m:
		print(' '.join(map(str, row)))
main()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	arr = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	arr[a][b] = 1
	if a == 0 and b == 0 or (a == 0 and b == 7) or (a == 7 and b == 0) or (a == 7 and b == 7):
		if a == 0 and b == 0:
			arr[2][1] = 2
		elif a == 0 and b == 7:
			arr[2][6] = 2
		elif a == 7 and b == 0:
			arr[5][1] = 2
		elif a == 7 and b == 7:
			arr[5][6] = 2
	elif b == 0 or a == 0 or b == 7 or (a == 7):
		if b == 0:
			arr[a - 1][2] = 2
			arr[a + 1][2] = 2
		elif a == 0:
			arr[2][b - 1] = 2
			arr[2][b + 1] = 2
		elif b == 7:
			arr[a - 1][5] = 2
			arr[a + 1][5] = 2
		elif a == 7:
			arr[5][b + 1] = 2
			arr[5][b - 1] = 2
	elif b + 3 <= 7:
		if a + 2 <= 7:
			arr[a - 1][b + 3] = 2
			arr[a + 2][b - 1] = 2
		else:
			arr[a + 1][b + 3] = 2
			arr[a - 2][b - 1] = 2
	elif a + 3 <= 7:
		arr[a - 1][b - 2] = 2
		arr[a + 3][b + 1] = 2
	else:
		arr[a + 1][b - 3] = 2
		arr[a - 2][b + 1] = 2
	for x in arr:
		print(*x)
	print()


from ctypes import pointer
mapInput = lambda : map(int, input().split())
listInput = lambda : list(mapInput())

class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def __add__(self, p):
		return Point(self.x + p.x, self.y + p.y)

	def __eq__(self, p):
		return self.x == p.x and self.y == p.y

	def isValid(self):
		return self.x >= 1 and self.x <= 8 and (self.y >= 1) and (self.y <= 8)
offsets = [Point(1, 2), Point(-1, 2), Point(1, -2), Point(-1, -2), Point(2, 1), Point(-2, 1), Point(2, -1), Point(-2, -1)]
for _ in range(int(input())):
	(y, x) = mapInput()
	kingPos = Point(x, y)
	queenPos = []
	if x == 1 and y == 1 or (x == 1 and y == 8) or (x == 8 and y == 1) or (x == 8 and y == 8):
		for offset in offsets:
			if (kingPos + offset).isValid():
				queenPos.append(kingPos + offset)
				break
	elif x == 1 or y == 1 or x == 8 or (y == 8):
		if (kingPos + offsets[0]).isValid() and (kingPos + offsets[1]).isValid():
			queenPos.append(kingPos + offsets[0])
			queenPos.append(kingPos + offsets[1])
		elif (kingPos + offsets[2]).isValid() and (kingPos + offsets[3]).isValid():
			queenPos.append(kingPos + offsets[2])
			queenPos.append(kingPos + offsets[3])
		elif (kingPos + offsets[4]).isValid() and (kingPos + offsets[6]).isValid():
			queenPos.append(kingPos + offsets[4])
			queenPos.append(kingPos + offsets[6])
		else:
			queenPos.append(kingPos + offsets[5])
			queenPos.append(kingPos + offsets[7])
	elif x == 2 and y == 2 or (x == 2 and y == 7) or (x == 7 and y == 2) or (x == 7 and y == 7):
		if x == 2 and y == 2:
			queenPos.append(kingPos + Point(2, -1))
			queenPos.append(kingPos + Point(-1, 3))
		elif x == 2 and y == 7:
			queenPos.append(kingPos + Point(-1, -2))
			queenPos.append(kingPos + Point(3, 1))
		elif x == 7 and y == 2:
			queenPos.append(kingPos + Point(-3, -1))
			queenPos.append(kingPos + Point(1, 2))
		else:
			queenPos.append(kingPos + Point(-2, 1))
			queenPos.append(kingPos + Point(1, -3))
	elif (kingPos + offsets[0]).isValid() and (kingPos + offsets[3]).isValid():
		queenPos.append(kingPos + offsets[0])
		queenPos.append(kingPos + offsets[3])
	else:
		queenPos.append(kingPos + offsets[4])
		queenPos.append(kingPos + offsets[7])
	outputString = ''
	for y in range(1, 9):
		for x in range(1, 9):
			if Point(x, y) == kingPos:
				outputString += '1'
			elif Point(x, y) in queenPos:
				outputString += '2'
			else:
				outputString += '0'
			if x != 8:
				outputString += ' '
		outputString += '\n'
	print(outputString)


t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	(x, y) = (x - 1, y - 1)
	B = [[0 for i in range(8)] for j in range(8)]
	B[x][y] = 1
	if x == 0:
		if y == 0:
			B[1][2] = 2
		elif y == 7:
			B[1][5] = 2
		else:
			B[x + 2][y - 1] = 2
			B[x + 2][y + 1] = 2
	elif x == 7:
		if y == 0:
			B[6][2] = 2
		elif y == 7:
			B[6][5] = 2
		else:
			B[x - 2][y - 1] = 2
			B[x - 2][y + 1] = 2
	elif y == 0:
		B[x + 1][y + 2] = 2
		B[x - 1][y + 2] = 2
	elif y == 7:
		B[x - 1][y - 2] = 2
		B[x + 1][y - 2] = 2
	elif x == 1:
		if y == 1:
			B[x - 1][y + 3] = 2
			B[x + 2][y - 1] = 2
		elif y == 6:
			B[x - 1][y - 2] = 2
			B[x + 3][y + 1] = 2
		else:
			B[x - 1][y - 2] = 2
			B[x + 1][y + 2] = 2
	elif x == 6:
		if y == 1:
			B[x + 1][y + 3] = 2
			B[x - 2][y - 1] = 2
		elif y == 6:
			B[x + 1][y - 3] = 2
			B[x - 2][y + 1] = 2
		else:
			B[x - 1][y - 2] = 2
			B[x + 1][y + 2] = 2
	elif y == 1:
		B[x - 2][y - 1] = 2
		B[x + 2][y + 1] = 2
	elif y == 6:
		B[x - 2][y + 1] = 2
		B[x + 2][y - 1] = 2
	else:
		B[x - 1][y - 2] = 2
		B[x + 1][y + 2] = 2
	for i in range(8):
		print(*B[i])


def print_chessboard(chessboard):
	for i in range(8):
		for j in range(8):
			print(chessboard[i][j], end=' ')
		print()

def minqueens(chessboard, a, b):
	if a == 1 and b == 1:
		chessboard[1][2] = 2
		return
	if a == 1 and b == 8:
		chessboard[1][5] = 2
		return
	if a == 8 and b == 1:
		chessboard[6][2] = 2
		return
	if a == 8 and b == 8:
		chessboard[6][5] = 2
		return
	if a == 1:
		chessboard[2][b] = 2
		chessboard[2][b - 2] = 2
		return
	if a == 8:
		chessboard[5][b] = 2
		chessboard[5][b - 2] = 2
		return
	if b == 1:
		chessboard[a][2] = 2
		chessboard[a - 2][2] = 2
		return
	if b == 8:
		chessboard[a][5] = 2
		chessboard[a - 2][5] = 2
		return
	if a == 7 and b == 7:
		chessboard[7][4] = 2
		chessboard[5][4] = 2
		chessboard[4][7] = 2
		return
	if b == 7:
		chessboard[a][b - 3] = 2
		chessboard[a - 2][b - 3] = 2
		chessboard[a + 1][b] = 2
		return
	if a == 7:
		chessboard[a][b + 1] = 2
		chessboard[a - 2][b + 1] = 2
		chessboard[4][b - 2] = 2
		return
	chessboard[a][b + 1] = 2
	chessboard[a - 2][b + 1] = 2
	chessboard[a + 1][b - 2] = 2
	return
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	B = [[0 for i in range(8)] for j in range(8)]
	B[a - 1][b - 1] = 1
	if a == 1 and b == 1:
		B[1][2] = 2
	elif a == 1 and b == 8:
		B[1][5] = 2
	elif a == 8 and b == 1:
		B[6][2] = 2
	elif a == 8 and b == 8:
		B[6][5] = 2
	elif a == 1:
		B[a + 1][b - 2] = 2
		B[a + 1][b] = 2
	elif a == 8:
		B[a - 3][b - 2] = 2
		B[a - 3][b] = 2
	elif b == 1:
		B[a][b + 1] = 2
		B[a - 2][b + 1] = 2
	elif b == 8:
		B[a - 2][b - 3] = 2
		B[a][b - 3] = 2
	elif a == 2 and b == 2:
		B[a - 2][b + 2] = 2
		B[a + 1][b - 2] = 2
	elif a == 2 and b == 7:
		B[a - 2][b - 3] = 2
		B[a + 2][b] = 2
	elif a == 7 and b == 2:
		B[a][b + 2] = 2
		B[a - 3][b - 2] = 2
	elif a == 7 and b == 7:
		B[a][b - 4] = 2
		B[a - 3][b] = 2
	elif a == 2:
		B[a - 2][b - 3] = 2
		B[a][b + 1] = 2
	elif a == 7:
		B[a - 2][b - 3] = 2
		B[a][b + 1] = 2
	elif b == 2:
		B[a - 3][b - 2] = 2
		B[a + 1][b] = 2
	elif b == 7:
		B[a - 3][b] = 2
		B[a + 1][b - 2] = 2
	else:
		B[a - 2][b - 3] = 2
		B[a][b + 1] = 2
	for i in range(8):
		print(*B[i])


test = int(input())
for t in range(test):
	(a, b) = map(int, input().split())
	B = [[0 for i in range(8)] for j in range(8)]
	B[a - 1][b - 1] = 1
	if a == 1 and b == 1:
		B[1][2] = 2
	elif a == 1 and b == 8:
		B[1][5] = 2
	elif a == 8 and b == 1:
		B[6][2] = 2
	elif a == 8 and b == 8:
		B[6][5] = 2
	elif a == 1:
		B[a + 1][b - 2] = 2
		B[a + 1][b] = 2
	elif a == 8:
		B[a - 3][b - 2] = 2
		B[a - 3][b] = 2
	elif b == 1:
		B[a][b + 1] = 2
		B[a - 2][b + 1] = 2
	elif b == 8:
		B[a - 2][b - 3] = 2
		B[a][b - 3] = 2
	elif a == 2 and b == 2:
		B[a - 2][b + 2] = 2
		B[a + 1][b - 2] = 2
	elif a == 2 and b == 7:
		B[a - 2][b - 3] = 2
		B[a + 2][b] = 2
	elif a == 7 and b == 2:
		B[a][b + 2] = 2
		B[a - 3][b - 2] = 2
	elif a == 7 and b == 7:
		B[a][b - 4] = 2
		B[a - 3][b] = 2
	elif a == 2:
		B[a - 2][b - 3] = 2
		B[a][b + 1] = 2
	elif a == 7:
		B[a - 2][b - 3] = 2
		B[a][b + 1] = 2
	elif b == 2:
		B[a - 3][b - 2] = 2
		B[a + 1][b] = 2
	elif b == 7:
		B[a - 3][b] = 2
		B[a + 1][b - 2] = 2
	else:
		B[a - 2][b - 3] = 2
		B[a][b + 1] = 2
	for i in range(8):
		print(*B[i])


def rotate_point(r, c):
	return (c, 8 - r - 1)

def rotate_grid(grid):
	r_grid = [[grid[r][c] for c in range(8)] for r in range(8)]
	for r in range(8):
		for c in range(8):
			(r2, c2) = rotate_point(r, c)
			r_grid[r2][c2] = grid[r][c]
	return r_grid

def get_queens(r, c):
	if r == 0 and c == 0:
		return [(1, 2)]
	elif r == 0:
		return [(2, c - 1), (2, c + 1)]
	elif c == 0:
		return [(r - 1, 2), (r + 1, 2)]
	else:
		return [(r + 3, c - 1), (r - 1, c + 2)]

def get_square(r, c):
	if r < 4 and c < 4:
		return 0
	elif r < 4:
		return 1
	elif c >= 4:
		return 2
	return 3

def g(r, c):
	grid = [[0 for i in range(8)] for j in range(8)]
	square = get_square(r, c)
	num_rotations = (4 - square) % 4
	(r2, c2) = (r, c)
	for i in range(num_rotations):
		(r2, c2) = rotate_point(r2, c2)
	grid[r2][c2] = 1
	queens = get_queens(r2, c2)
	for (qr, qc) in queens:
		grid[qr][qc] = 2
	for i in range(square):
		grid = rotate_grid(grid)
	return grid

def print_grid(grid):
	for r in range(len(grid)):
		row = ' '.join(map(str, grid[r]))
		print(row)
t = int(input())
for i in range(t):
	(a, b) = [int(el) for el in input().split(' ')]
	r = a - 1
	c = b - 1
	print_grid(g(r, c))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())

def valid(x, y):
	if x <= 0 or x > 8 or y <= 0 or (y > 8):
		return 0
	return 1
t = inp()
while t:
	t -= 1
	(x, y) = ma()
	res = [[0 for i in range(8)] for j in range(8)]
	res[x - 1][y - 1] = 1
	if x == 1 and y == 1:
		res[2][1] = 2
	elif x == 1 and y == 8:
		res[2][6] = 2
	elif x == 8 and y == 1:
		res[5][1] = 2
	elif x == 8 and y == 8:
		res[5][6] = 2
	elif x in [1, 8] or y in [1, 8]:
		if x == 1:
			res[x + 1][y - 2] = 2
			res[x + 1][y] = 2
		if x == 8:
			res[x - 3][y - 2] = 2
			res[x - 3][y] = 2
		if y == 1:
			res[x - 2][y + 1] = 2
			res[x][y + 1] = 2
		if y == 8:
			res[x - 2][y - 3] = 2
			res[x][y - 3] = 2
	else:
		flag = 0
		for i1 in [-1, 1]:
			for i2 in [-2, 2]:
				for i3 in [-3, 3]:
					for i4 in [-1, 1]:
						(x1, x2) = (x + i1, x + i3)
						(y1, y2) = (y + i2, y + i4)
						if valid(x1, y1) and valid(x2, y2) and (flag == 0) and (i1 > 0 and i3 < 0 or (i1 < 0 and i3 > 0)) and (i2 > 0 and i4 < 0 or (i2 < 0 and i4 > 0)):
							res[x1 - 1][y1 - 1] = 2
							res[x2 - 1][y2 - 1] = 2
							flag = 1
	for i in res:
		print(*i)


T = int(input())
for t in range(T):
	(x, y) = map(int, input().split())
	ans = [[0 for i in range(8)] for j in range(8)]
	extremes = [[1, 1], [8, 8], [8, 1], [1, 8]]
	threes = [[2, 2], [7, 2], [2, 7], [7, 7]]
	ans[x - 1][y - 1] = 1
	if [x, y] in extremes:
		(a, b) = (0, 0)
		if x < 4:
			a = 2
		else:
			a = 5
		if y < 4:
			b = 1
		else:
			b = 6
		ans[a][b] = 2
	elif [x, y] in threes:
		a = b = 0
		if y < 4:
			b = 3
		else:
			b = 4
		if x < 4:
			a = 0
		else:
			a = 7
		ans[a][b] = 2
		if y < 4:
			b = 0
		else:
			b = 7
		if x < 4:
			a = 4
		else:
			a = 3
		ans[a][b] = 2
	elif x == 1 or x == 8 or y == 1 or (y == 8):
		if x == 1:
			ans[2][y - 2] = 2
			ans[2][y] = 2
		elif x == 8:
			ans[5][y - 2] = 2
			ans[5][y] = 2
		elif y == 1:
			ans[x - 2][2] = 2
			ans[x][2] = 2
		else:
			ans[x - 2][5] = 2
			ans[x][5] = 2
	elif y == 2 or y == 7:
		ans[x - 3][y - 2] = 2
		ans[x + 1][y] = 2
	else:
		ans[x - 2][y - 3] = 2
		ans[x][y + 1] = 2
	for i in range(8):
		print(*ans[i])


from math import ceil, floor

def valid(x, y):
	if x <= 0 or x > 8 or y <= 0 or (y > 8):
		return 0
	return 1

def ma():
	return map(int, input().split())

def solve2():
	(x, y) = ma()
	res = [[0 for i in range(8)] for j in range(8)]
	res[x - 1][y - 1] = 1
	if x == 1 and y == 1:
		res[2][1] = 2
	elif x == 1 and y == 8:
		res[2][6] = 2
	elif x == 8 and y == 1:
		res[5][1] = 2
	elif x == 8 and y == 8:
		res[5][6] = 2
	elif x in [1, 8] or y in [1, 8]:
		if x == 1:
			res[x + 1][y - 2] = 2
			res[x + 1][y] = 2
		if x == 8:
			res[x - 3][y - 2] = 2
			res[x - 3][y] = 2
		if y == 1:
			res[x - 2][y + 1] = 2
			res[x][y + 1] = 2
		if y == 8:
			res[x - 2][y - 3] = 2
			res[x][y - 3] = 2
	else:
		f = 0
		for i in [-1, 1]:
			for j in [-2, 2]:
				for k in [-3, 3]:
					for l in [-1, 1]:
						(x1, x2, y1, y2) = (x + i, x + k, y + j, y + l)
						if valid(x1, y1) and valid(x2, y2) and (f == 0) and (i > 0 and k < 0 or (i < 0 and k > 0)) and (j > 0 and l < 0 or (j < 0 and l > 0)):
							res[x1 - 1][y1 - 1] = 2
							res[x2 - 1][y2 - 1] = 2
							f = 1
	for i in res:
		print(*i)

def solve1():
	for _ in range(int(input())):
		solve2()
solve1()


t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split(' '))
	a = a - 1
	b = b - 1
	L = [['0', '0', '0', '0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0', '0', '0', '0']]
	L[a][b] = '1'
	if a == 0 and b == 0:
		L[a + 2][b + 1] = '2'
	elif a == 7 and b == 0:
		L[a - 2][b + 1] = '2'
	elif a == 0 and b == 7:
		L[a + 2][b - 1] = '2'
	elif a == 7 and b == 7:
		L[a - 2][b - 1] = '2'
	elif a < 7 and b == 0:
		L[a + 1][b + 2] = '2'
		L[a - 1][b + 2] = '2'
	elif a == 0 and b < 7:
		L[a + 2][b + 1] = '2'
		L[a + 2][b - 1] = '2'
	elif a < 7 and b == 7:
		L[a + 1][b - 2] = '2'
		L[a - 1][b - 2] = '2'
	elif a == 7 and b < 7:
		L[a - 2][b + 1] = '2'
		L[a - 2][b - 1] = '2'
	elif a <= 3 and b <= 3:
		L[a + 3][b - 1] = '2'
		L[a - 1][b + 2] = '2'
	elif a > 3 and b <= 3:
		L[a - 3][b - 1] = '2'
		L[a + 1][b + 2] = '2'
	elif a <= 3 and b > 3:
		L[a + 3][b + 1] = '2'
		L[a - 1][b - 2] = '2'
	elif a > 3 and b > 3:
		L[a - 3][b + 1] = '2'
		L[a + 1][b - 2] = '2'
	for j in range(0, 8):
		print(' '.join(L[j]))


for Queen in range(int(input())):
	(x, y) = map(int, input().split())
	(x, y) = (x - 1, y - 1)
	l = []
	for i in range(8):
		l.append([0] * 8)
	l[x][y] = 1
	if x == 0 and y == 0:
		l[2][1] = 2
	elif x == 7 and y == 0:
		l[6][2] = 2
	elif x == 0 and y == 7:
		l[2][6] = 2
	elif x == 7 and y == 7:
		l[6][5] = 2
	elif x == 0:
		l[2][y + 1] = 2
		l[2][y - 1] = 2
	elif y == 0:
		l[x + 1][2] = 2
		l[x - 1][2] = 2
	elif x == 7:
		l[5][y + 1] = 2
		l[5][y - 1] = 2
	elif y == 7:
		l[x + 1][5] = 2
		l[x - 1][5] = 2
	elif x > 2 and y > 2:
		l[x + 1][y - 2] = 2
		l[x - 3][y + 1] = 2
	elif x < 3 and y < 3:
		l[x - 1][y + 2] = 2
		l[x + 3][y - 1] = 2
	elif y > 2 and x < 3:
		l[x - 1][y - 2] = 2
		l[x + 3][y + 1] = 2
	elif y < 3 and x > 2:
		l[x + 1][y + 2] = 2
		l[x - 3][y - 1] = 2
	for i in l:
		print(*i)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	arr = [[0] * 8 for i in range(8)]
	arr[a - 1][b - 1] = 1
	if a in (1, 8) and b in (1, 8):
		a = a - 1 if a == 8 else a + 1
		b = b - 2 if b == 8 else b + 2
		arr[a - 1][b - 1] = 2
	elif a == 1:
		arr[a + 1][b - 2] = 2
		arr[a + 1][b] = 2
	elif a == 8:
		arr[a - 3][b - 2] = 2
		arr[a - 3][b] = 2
	elif b == 1:
		arr[a][b + 1] = 2
		arr[a - 2][b + 1] = 2
	elif b == 8:
		arr[a - 2][b - 3] = 2
		arr[a][b - 3] = 2
	elif a == 2 and b == 2:
		arr[a - 2][b + 2] = 2
		arr[a + 1][b - 2] = 2
	elif a == 2 and b == 7:
		arr[a - 2][b - 3] = 2
		arr[a + 2][b] = 2
	elif a == 7 and b == 2:
		arr[a][b + 2] = 2
		arr[a - 3][b - 2] = 2
	elif a == 7 and b == 7:
		arr[a][b - 4] = 2
		arr[a - 3][b] = 2
	elif a == 2:
		arr[a - 2][b - 3] = 2
		arr[a][b + 1] = 2
	elif a == 7:
		arr[a - 2][b - 3] = 2
		arr[a][b + 1] = 2
	elif b == 2:
		arr[a - 3][b - 2] = 2
		arr[a + 1][b] = 2
	elif b == 7:
		arr[a - 3][b] = 2
		arr[a + 1][b - 2] = 2
	else:
		arr[a - 2][b - 3] = 2
		arr[a][b + 1] = 2
	for r in arr:
		print(*r)


def valid(x, y):
	return 0 if x <= 0 or x > 8 or y <= 0 or (y > 8) else 1
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	res = [[0 for i in range(8)] for j in range(8)]
	res[x - 1][y - 1] = 1
	if x == 1 and y == 1:
		res[2][1] = 2
	elif x == 1 and y == 8:
		res[2][6] = 2
	elif x == 8 and y == 1:
		res[5][1] = 2
	elif x == 8 and y == 8:
		res[5][6] = 2
	elif x in [1, 8] or y in [1, 8]:
		if x == 1:
			res[x + 1][y - 2] = 2
			res[x + 1][y] = 2
		if x == 8:
			res[x - 3][y - 2] = 2
			res[x - 3][y] = 2
		if y == 1:
			res[x - 2][y + 1] = 2
			res[x][y + 1] = 2
		if y == 8:
			res[x - 2][y - 3] = 2
			res[x][y - 3] = 2
	else:
		flag = 0
		for i1 in [-1, 1]:
			for i2 in [-2, 2]:
				for i3 in [-3, 3]:
					for i4 in [-1, 1]:
						(x1, x2) = (x + i1, x + i3)
						(y1, y2) = (y + i2, y + i4)
						if valid(x1, y1) and valid(x2, y2) and (flag == 0) and (i1 > 0 and i3 < 0 or (i1 < 0 and i3 > 0)) and (i2 > 0 and i4 < 0 or (i2 < 0 and i4 > 0)):
							res[x1 - 1][y1 - 1] = 2
							res[x2 - 1][y2 - 1] = 2
							flag = 1
	for i in res:
		print(*i)


from collections import defaultdict
import sys

def solve():
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	hs = defaultdict(lambda : defaultdict(int))
	hs[a][b] = 1
	ans = []
	if b == 0:
		if a == 0:
			hs[a + 1][b + 2] = 2
		elif a == 7:
			hs[a - 1][b + 2] = 2
		else:
			hs[a - 1][b + 2] = 2
			hs[a + 1][b + 2] = 2
	elif b == 7:
		if a == 0:
			hs[a + 1][b - 2] = 2
		elif a == 7:
			hs[a - 1][b - 2] = 2
		else:
			hs[a - 1][b - 2] = 2
			hs[a + 1][b - 2] = 2
	elif a == 0:
		if b == 0:
			hs[a + 2][b + 1] = 2
		elif b == 7:
			hs[a + 2][b - 1] = 2
		else:
			hs[a + 2][b - 1] = 2
			hs[a + 2][b + 1] = 2
	elif a == 7:
		if b == 0:
			hs[a - 2][b + 1] = 2
		elif b == 7:
			hs[a - 2][b - 1] = 2
		else:
			hs[a - 2][b - 1] = 2
			hs[a - 2][b + 1] = 2
	elif a == 1 and b == 1:
		hs[a - 1][b + 3] = 2
		hs[a + 2][b - 1] = 2
	elif a == 6 and b == 1:
		hs[a + 1][b + 3] = 2
		hs[a - 2][b - 1] = 2
	elif a == 1 and b == 6:
		hs[a - 1][b - 3] = 2
		hs[a + 2][b + 1] = 2
	elif a == 6 and b == 6:
		hs[a + 1][b - 3] = 2
		hs[a - 2][b + 1] = 2
	elif b - 2 >= 0 and b + 2 <= 7:
		hs[a - 1][b + 2] = 2
		hs[a + 1][b - 2] = 2
	else:
		hs[a - 2][b + 1] = 2
		hs[a + 2][b - 1] = 2
	for x in range(0, 8):
		A = [hs[x][i] for i in range(0, 8)]
		print(' '.join(map(str, A)))
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	(i, j) = [int(x) for x in input().split()]
	grid = [[0 for i in range(8)] for j in range(8)]
	grid[i - 1][j - 1] = 1
	if i == 1 and j == 1:
		grid[2 - 1][3 - 1] = 2
	elif i == 1 and j == 8:
		grid[2 - 1][6 - 1] = 2
	elif i == 8 and j == 1:
		grid[7 - 1][3 - 1] = 2
	elif i == 8 and j == 8:
		grid[7 - 1][6 - 1] = 2
	elif i == 1:
		grid[i + 2 - 1][j - 1 - 1] = 2
		grid[i + 2 - 1][j + 1 - 1] = 2
	elif i == 8:
		grid[i - 2 - 1][j - 1 - 1] = 2
		grid[i - 2 - 1][j + 1 - 1] = 2
	elif j == 1:
		grid[i - 1 - 1][j + 2 - 1] = 2
		grid[i + 1 - 1][j + 2 - 1] = 2
	elif j == 8:
		grid[i - 1 - 1][j - 2 - 1] = 2
		grid[i + 1 - 1][j - 2 - 1] = 2
	elif i == 2 and j == 2:
		grid[i - 1 - 1][j + 3 - 1] = 2
		grid[i + 2 - 1][j - 1 - 1] = 2
	elif i == 2 and j == 7:
		grid[i - 1 - 1][j - 2 - 1] = 2
		grid[i + 3 - 1][j + 1 - 1] = 2
	elif i == 7 and j == 2:
		grid[i + 1 - 1][j + 3 - 1] = 2
		grid[i - 2 - 1][j - 1 - 1] = 2
	elif i == 7 and j == 7:
		grid[i + 1 - 1][j - 3 - 1] = 2
		grid[i - 2 - 1][j + 1 - 1] = 2
	elif i == 2:
		grid[i - 1 - 1][j - 2 - 1] = 2
		grid[i + 1 - 1][j + 2 - 1] = 2
	elif i == 7:
		grid[i - 1 - 1][j - 2 - 1] = 2
		grid[i + 1 - 1][j + 2 - 1] = 2
	elif j == 2:
		grid[i - 2 - 1][j - 2] = 2
		grid[i + 2 - 1][j] = 2
	elif j == 7:
		grid[i - 2 - 1][j + 1 - 1] = 2
		grid[i + 2 - 1][j - 1 - 1] = 2
	else:
		grid[i - 1 - 1][j - 2 - 1] = 2
		grid[i + 1 - 1][j + 2 - 1] = 2
	for i in range(8):
		print(*grid[i])


T = int(input())
while T:
	(X, Y) = map(int, input().split(' '))
	mat = []
	for i in range(8):
		mat.append([0, 0, 0, 0, 0, 0, 0, 0])
	mat[X - 1][Y - 1] = 1
	if X == 1 and Y == 1 or (X == 1 and Y == 8) or (X == 8 and Y == 8) or (X == 8 and Y == 1):
		if X == 1:
			X1 = 3
		if X == 8:
			X1 = 6
		if Y == 1:
			Y1 = 2
		if Y == 8:
			Y1 = 7
		mat[X1 - 1][Y1 - 1] = 2
	elif X == 1 and Y > 1 or (X > 1 and Y == 8) or (X == 8 and Y > 1) or (X > 1 and Y == 1):
		if X == 1:
			X1 = 3
			X2 = 3
			Y1 = Y - 1
			Y2 = Y + 1
		if X == 8:
			X1 = 6
			X2 = 6
			Y1 = Y - 1
			Y2 = Y + 1
		if Y == 1:
			Y1 = 3
			Y2 = 3
			X1 = X - 1
			X2 = X + 1
		if Y == 8:
			Y1 = 6
			Y2 = 6
			X1 = X - 1
			X2 = X + 1
		mat[X1 - 1][Y1 - 1] = 2
		mat[X2 - 1][Y2 - 1] = 2
	elif X == 2 and Y == 2 or (X == 2 and Y == 7) or (X == 7 and Y == 2) or (X == 7 and Y == 7):
		if X == 2 and Y == 2:
			X1 = 5
			X2 = 1
			Y1 = 1
			Y2 = 4
		if X == 2 and Y == 7:
			X1 = 1
			X2 = 5
			Y1 = 5
			Y2 = 8
		if X == 7 and Y == 7:
			X1 = 5
			X2 = 8
			Y1 = 8
			Y2 = 4
		if X == 7 and Y == 2:
			X1 = 8
			X2 = 4
			Y1 = 4
			Y2 = 1
		mat[X1 - 1][Y1 - 1] = 2
		mat[X2 - 1][Y2 - 1] = 2
	else:
		if X == 2 or X == 7:
			X1 = X + 1
			Y1 = Y - 2
			X2 = X - 1
			Y2 = Y + 2
		elif Y == 2 or Y == 7:
			Y1 = Y + 1
			X1 = X - 2
			Y2 = Y - 1
			X2 = X + 2
		else:
			X1 = X + 1
			Y1 = Y - 2
			X2 = X - 1
			Y2 = Y + 2
		mat[X1 - 1][Y1 - 1] = 2
		mat[X2 - 1][Y2 - 1] = 2
	for i in range(8):
		print(*mat[i], sep=' ')
	T -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	n -= 1
	m -= 1
	board = [[0 for i in range(8)] for j in range(8)]
	board[n][m] = 1
	if n == 0 and m == 0 or (n == 0 and m == 7) or (n == 7 and m == 0) or (n == 7 and m == 7):
		pos = [[n + 1, m + 2], [n - 1, m + 2], [n + 1, m - 2], [n - 1, m - 2]]
		cnt = 0
		for (x, y) in pos:
			if cnt == 1:
				break
			if 0 <= x <= 7 and 0 <= y <= 7:
				board[x][y] = 2
				cnt += 1
	elif n == 0 or m == 0 or n == 7 or (m == 7):
		pos = [[n + 1, m + 2], [n - 1, m + 2], [n + 1, m - 2], [n - 1, m - 2], [n + 2, m - 1], [n + 2, m + 1], [n - 2, m - 1], [n - 2, m + 1]]
		cnt = 0
		for (x, y) in pos:
			if cnt == 2:
				break
			if 0 <= x <= 7 and 0 <= y <= 7:
				board[x][y] = 2
				cnt += 1
	elif n == 1 and m == 1 or (n == 6 and m == 6) or (n == 1 and m == 6) or (n == 6 and m == 1):
		if n == 1 and m == 1:
			board[n + 3][m - 1] = 2
			board[n - 1][m + 2] = 2
		elif n == 6 and m == 6:
			board[n + 1][m - 3] = 2
			board[n - 2][m + 1] = 2
		elif n == 1 and m == 6:
			board[n + 3][m + 1] = 2
			board[n - 1][m - 2] = 2
		elif n == 6 and m == 1:
			board[n + 1][m + 2] = 2
			board[n - 3][m - 1] = 2
	else:
		if 2 <= m <= 5:
			pos = [[n + 1, m + 2], [n - 1, m - 2]]
		else:
			pos = [[n + 2, m + 1], [n - 2, m - 1]]
		for (x, y) in pos:
			board[x][y] = 2
	for row in board:
		print(*row)


import math
from collections import Counter
ints = lambda : list(map(int, input().split()))
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
mx = 10 ** 5
inp = lambda : int(input())
for _ in range(inp()):
	(a, b) = ints()
	(org_a, org_b) = (a, b)
	if org_a in (1, 8) and org_b in (1, 8):
		queens = [[2, 3]]
	elif org_b in (1, 8):
		b = 1
		if org_a > 4:
			a = 9 - a
		queens = [[a - 1, b + 2], [a + 1, b + 2]]
	elif org_a in (1, 8):
		a = 1
		if org_b > 4:
			b = 9 - b
		queens = [[a + 2, b - 1], [a + 2, b + 1]]
	else:
		if org_a > 4:
			a = 9 - a
		if org_b > 4:
			b = 9 - b
		if a == 2 and b == 2:
			queens = [[a + 3, b - 1], [a - 1, b + 2]]
		elif b - 2 > 0 and a - 1 > 0:
			queens = [[a - 1, b - 2], [a + 1, b + 2]]
		else:
			queens = [[a - 2, b - 1], [a + 2, b + 1]]
	for queen in queens:
		if org_a > 4:
			queen[0] = 9 - queen[0]
		if org_b > 4:
			queen[1] = 9 - queen[1]
	board = []
	for _ in range(8):
		board.append([0 for _ in range(8)])
	board[org_a - 1][org_b - 1] = 1
	for (queen_r, queen_c) in queens:
		board[queen_r - 1][queen_c - 1] = 2
	for row in board:
		print(*row)


for _ in range(int(input())):
	coor = [int(i) for i in input().split()]
	kx = coor[0]
	ky = coor[1]

	def printoutput(kx, ky, q1x, q1y, q2x=0, q2y=0):
		mat = [[0] * 8 for _ in range(8)]
		mat[kx - 1][ky - 1] = 1
		mat[q1x - 1][q1y - 1] = 2
		if q2x != 0:
			mat[q2x - 1][q2y - 1] = 2
		for row in mat:
			print(*row)
	if kx == 1 and ky == 1:
		q1x = kx + 1
		q1y = ky + 2
		printoutput(kx, ky, q1x, q1y)
		continue
	elif kx == 1 and ky == 8:
		q1x = kx + 1
		q1y = ky - 2
		printoutput(kx, ky, q1x, q1y)
		continue
	elif kx == 8 and ky == 8:
		q1x = kx - 1
		q1y = ky - 2
		printoutput(kx, ky, q1x, q1y)
		continue
	elif kx == 8 and ky == 1:
		q1x = kx - 1
		q1y = ky + 2
		printoutput(kx, ky, q1x, q1y)
		continue
	if kx == 1:
		q1x = kx + 2
		q1y = ky - 1
		q2x = kx + 2
		q2y = ky + 1
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue
	elif kx == 8:
		q1x = kx - 2
		q1y = ky - 1
		q2x = kx - 2
		q2y = ky + 1
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue
	elif ky == 1:
		q1x = kx - 1
		q1y = ky + 2
		q2x = kx + 1
		q2y = ky + 2
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue
	elif ky == 8:
		q1x = kx - 1
		q1y = ky - 2
		q2x = kx + 1
		q2y = ky - 2
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue
	if ky == 2 and kx == 2:
		q1x = kx - 1
		q1y = ky + 2
		q2x = kx + 3
		q2y = ky - 1
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue
	elif ky == 2 and kx == 7:
		q1x = kx + 1
		q1y = ky + 2
		q2x = kx - 3
		q2y = ky - 1
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue
	elif ky == 7 and kx == 2:
		q1x = kx - 1
		q1y = ky - 2
		q2x = kx + 3
		q2y = ky + 1
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue
	elif ky == 7 and kx == 7:
		q1x = kx + 1
		q1y = ky - 2
		q2x = kx - 3
		q2y = ky + 1
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue
	elif ky == 2 or ky == 7:
		q1x = kx - 2
		q1y = ky - 1
		q2x = kx + 2
		q2y = ky + 1
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue
	else:
		q1x = kx - 1
		q1y = ky + 2
		q2x = kx + 1
		q2y = ky - 2
		printoutput(kx, ky, q1x, q1y, q2x, q2y)
		continue


t = int(input())

def wtf(x, y):
	if x == 2 and y == 2:
		return (1, 1)
	if x == 2 and y == 7:
		return (1, 8)
	if x == 7 and y == 2:
		return (8, 1)
	if x == 7 and y == 7:
		return (8, 8)

def shift(s, n):
	if s + n < 9:
		return s + n
	else:
		return s - n

def print_board(Q, X):
	b = [[0 for i in range(8)] for j in range(8)]
	for q in Q:
		b[q[0] - 1][q[1] - 1] = 2
	b[X[0] - 1][X[1] - 1] = 1
	for bb in b:
		print(*bb)
for i in range(t):
	(x, y) = list(map(int, input().split()))
	Q = []
	if x in [1, 8] and y in [1, 8]:
		Q.append((shift(x, 2), shift(y, 1)))
	elif x in [1, 8]:
		Q.append((shift(x, 2), y - 1))
		Q.append((shift(x, 2), y + 1))
	elif y in [1, 8]:
		Q.append((x - 1, shift(y, 2)))
		Q.append((x + 1, shift(y, 2)))
	elif x in [3, 4, 5, 6]:
		Q.append((x + 2, y - 1))
		Q.append((x - 2, y + 1))
	elif y in [3, 4, 5, 6]:
		Q.append((x - 1, y + 2))
		Q.append((x + 1, y - 2))
	else:
		Q.append((shift(x, 2), wtf(x, y)[1]))
		Q.append((wtf(x, y)[0], shift(y, 3)))
	print_board(Q, (x, y))


import math
from bisect import bisect, bisect_left, bisect_right
import heapq
from math import gcd, floor, sqrt, log
from collections import defaultdict as ddc
from collections import Counter

def intin():
	return int(input())

def mapin():
	return map(int, input().split())

def strin():
	return input().split()
INF = 10 ** 20
mod = 1000000007

def LIS(arr, n):
	dp = [10 ** 9] * (n + 1)
	for ele in arr:
		dp[bisect_left(dp, ele)] = ele
	return bisect_left(dp, 10 ** 9)

def exponentiation(bas, exp, mod=1000000007):
	t = 1
	while exp > 0:
		if exp % 2 != 0:
			t = t * bas % mod
		bas = bas * bas % mod
		exp //= 2
	return t % mod

def MOD(p, q=1, mod=1000000007):
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p
yes = 'YES'
no = 'NO'
even = 'EVEN'
odd = 'ODD'

def check(do):
	(aa, bb) = do
	if -1 < aa < 8 and -1 < bb < 8:
		return True
	return False

def sett(arr, do):
	(aa, bb) = do
	if -1 < aa < 8 and -1 < bb < 8:
		arr[aa][bb] = 2

def process(a, b):
	arr = [[0] * 8 for i in range(8)]
	n = 8
	(x, y) = (a - 1, b - 1)
	arr[x][y] = 1
	if 1 < x < 6 and 0 < y < 7:
		arr[x - 2][y - 1] = 2
		arr[x + 2][y + 1] = 2
	elif x == 0 and y == 0:
		arr[x + 1][y + 2] = 2
	elif x == 0 and y == n - 1:
		arr[x + 1][y - 2] = 2
	elif x == n - 1 and y == 0:
		arr[x - 1][y + 2] = 2
	elif x == n - 1 and y == n - 1:
		arr[x - 1][y - 2] = 2
	elif x == 0:
		if y <= 5:
			arr[x + 1][y + 2] = 2
			arr[x + 2][y - 1] = 2
		else:
			arr[x + 1][y - 2] = 2
			arr[x + 2][y + 1] = 2
	elif x == 7:
		if y <= 5:
			arr[x - 1][y + 2] = 2
			arr[x - 2][y - 1] = 2
		else:
			arr[x - 1][y - 2] = 2
			arr[x - 2][y + 1] = 2
	elif x == 1:
		if y == 0:
			arr[x + 1][y + 2] = 2
			arr[x - 1][y + 2] = 2
		elif y == 7:
			arr[x + 1][y - 2] = 2
			arr[x - 1][y - 2] = 2
		elif y <= 4:
			arr[x + 2][y - 1] = 2
			arr[x - 1][y + 3] = 2
		else:
			arr[x + 2][y + 1] = 2
			arr[x - 1][y - 3] = 2
	elif x == 6:
		if y == 0:
			arr[x + 1][y + 2] = 2
			arr[x - 1][y + 2] = 2
		elif y == 7:
			arr[x + 1][y - 2] = 2
			arr[x - 1][y - 2] = 2
		elif y <= 4:
			arr[x - 2][y - 1] = 2
			arr[x + 1][y + 3] = 2
		else:
			arr[x - 2][y + 1] = 2
			arr[x + 1][y - 3] = 2
	else:
		tleft = [x - 1, y - 2]
		bleft = [x + 1, y - 2]
		tright = [x - 1, y + 2]
		bright = [x + 1, y + 2]
		if check(tleft) and check(bleft):
			sett(arr, tleft)
			sett(arr, bleft)
		elif check(tright) and check(bright):
			sett(arr, tright)
			sett(arr, bright)
		elif check(tleft) and check(tright):
			sett(arr, tleft)
			sett(arr, tright)
		else:
			sett(arr, bleft)
			sett(arr, bright)
	for row in arr:
		print(*row)

def main():
	for _ in range(int(input())):
		(a, b) = list(mapin())
		process(a, b)
main()


for tc in range(int(input())):
	(r, c) = map(int, input().split())
	if c == 1 and r == 1:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 3 and col == 2:
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif c == 8 and r == 8:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 6 and col == 7:
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif c == 1 and r == 8:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 7 and col == 3:
					if col == 8:
						print(2, end='')
					print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif c == 8 and r == 1:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 3 and col == 7:
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif c == 1:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == r - 1 and col == 3 or (row == r + 1 and col == 3):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif c == 8:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == r - 1 and col == 6 or (row == r + 1 and col == 6):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif r == 1:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 3 and col == c - 1 or (row == 3 and col == c + 1):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif r == 8:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 6 and col == c - 1 or (row == 6 and col == c + 1):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif r == 2 and c == 7:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 1 and col == 4 or (row == 4 and col == 8):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif c == 2 and r == 7:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 4 and col == 1 or (row == 8 and col == 4):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif c == 7 and r == 7:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 4 and col == 8 or (row == 8 and col == 5):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif c == 2 and r == 2:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == 1 and col == 5 or (row == 4 and col == 1):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif r == 2 or r == 7:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == r - 1 and col == c - 2 or (row == r + 1 and col == c + 2):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	elif c == 2 or c == 7:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == r - 2 and col == c - 1 or (row == r + 2 and col == c + 1):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	else:
		for row in range(1, 9):
			for col in range(1, 9):
				if row == r - 2 and col == c - 1 or (row == r + 2 and col == c + 1):
					if col == 8:
						print(2, end='')
					else:
						print(2, end=' ')
				elif row == r and col == c:
					if col == 8:
						print(1, end='')
					else:
						print(1, end=' ')
				elif col == 8:
					print(0, end='')
				else:
					print(0, end=' ')
			if row != 8:
				print()
	print()
	print()


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	ch = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	a -= 1
	b -= 1
	ch[a][b] = 1
	if a == 0:
		if b == 0:
			ch[2][1] = 2
		elif b == 7:
			ch[2][6] = 2
		else:
			ch[2][b - 1] = 2
			ch[2][b + 1] = 2
	elif a == 7:
		if b == 0:
			ch[5][1] = 2
		elif b == 7:
			ch[5][6] = 2
		else:
			ch[5][b - 1] = 2
			ch[5][b + 1] = 2
	elif a == 1:
		if b == 0:
			ch[a - 1][2] = 2
			ch[a + 1][2] = 2
		elif b == 7:
			ch[a - 1][5] = 2
			ch[a + 1][5] = 2
		elif b == 1:
			ch[0][4] = 2
			ch[3][0] = 2
		elif b == 6:
			ch[0][3] = 2
			ch[3][7] = 2
		else:
			ch[a - 1][b + 2] = 2
			ch[a + 1][b - 2] = 2
	elif a == 6:
		if b == 0:
			ch[a - 1][2] = 2
			ch[a + 1][2] = 2
		elif b == 7:
			ch[a - 1][5] = 2
			ch[a + 1][5] = 2
		elif b == 1:
			ch[7][4] = 2
			ch[4][0] = 2
		elif b == 6:
			ch[7][3] = 2
			ch[4][7] = 2
		else:
			ch[a - 1][b + 2] = 2
			ch[a + 1][b - 2] = 2
	elif b == 0:
		ch[a - 1][2] = 2
		ch[a + 1][2] = 2
	elif b == 7:
		ch[a - 1][5] = 2
		ch[a + 1][5] = 2
	elif b == 1:
		ch[a - 2][2] = 2
		ch[a + 2][0] = 2
	elif b == 6:
		ch[a - 2][7] = 2
		ch[a + 2][5] = 2
	else:
		ch[a - 1][b + 2] = 2
		ch[a + 1][b - 2] = 2
	for j in ch:
		print(*j)


def solve(a, b):
	if a == 1 and b == 1:
		return [2, 3]
	if a == 1 and b == 8:
		return [2, 6]
	if a == 8 and b == 1:
		return [7, 3]
	if a == 8 and b == 8:
		return [7, 6]
	if a == 1:
		return [3, b - 1, 3, b + 1]
	if a == 8:
		return [6, b - 1, 6, b + 1]
	if b == 1:
		return [a - 1, 3, a + 1, 3]
	if b == 8:
		return [a - 1, 6, a + 1, 6]
	if a == 2 and b == 2:
		return [1, 4, 5, 1]
	if a == 2 and b == 7:
		return [1, 5, 5, 8]
	if a == 7 and b == 2:
		return [8, 4, 4, 1]
	if a == 7 and b == 7:
		return [8, 5, 4, 8]
	if a > 2 and a < 7:
		return [a + 2, b - 1, a - 2, b + 1]
	return [a + 1, b + 2, a - 1, b - 2]
for _ in range(int(input())):
	grid = []
	for i in range(8):
		x = []
		for j in range(8):
			x.append(0)
		grid.append(x)
	(a, b) = map(int, input().split())
	alpha = solve(a, b)
	grid[a - 1][b - 1] = 1
	i = 0
	while i < len(alpha):
		grid[alpha[i] - 1][alpha[i + 1] - 1] = 2
		i += 2
	for i in grid:
		print(*i)


for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	board = [[0 for i in range(8)] for j in range(8)]
	board[a - 1][b - 1] = 1
	if a == 1 and b == 1:
		board[2 - 1][3 - 1] = 2
	elif a == 1 and b == 8:
		board[2 - 1][6 - 1] = 2
	elif a == 8 and b == 1:
		board[7 - 1][3 - 1] = 2
	elif a == 8 and b == 8:
		board[7 - 1][6 - 1] = 2
	elif a == 1:
		board[a + 2 - 1][b - 1 - 1] = 2
		board[a + 2 - 1][b + 1 - 1] = 2
	elif a == 8:
		board[a - 2 - 1][b - 1 - 1] = 2
		board[a - 2 - 1][b + 1 - 1] = 2
	elif b == 1:
		board[a - 1 - 1][b + 2 - 1] = 2
		board[a + 1 - 1][b + 2 - 1] = 2
	elif b == 8:
		board[a - 1 - 1][b - 2 - 1] = 2
		board[a + 1 - 1][b - 2 - 1] = 2
	elif a == 2 and b == 2:
		board[a - 1 - 1][b + 3 - 1] = 2
		board[a + 2 - 1][b - 1 - 1] = 2
	elif a == 2 and b == 7:
		board[a - 1 - 1][b - 2 - 1] = 2
		board[a + 3 - 1][b + 1 - 1] = 2
	elif a == 7 and b == 2:
		board[a + 1 - 1][b + 3 - 1] = 2
		board[a - 2 - 1][b - 1 - 1] = 2
	elif a == 7 and b == 7:
		board[a + 1 - 1][b - 3 - 1] = 2
		board[a - 2 - 1][b + 1 - 1] = 2
	elif a == 2:
		board[a - 1 - 1][b - 2 - 1] = 2
		board[a + 1 - 1][b + 2 - 1] = 2
	elif a == 7:
		board[a - 1 - 1][b - 2 - 1] = 2
		board[a + 1 - 1][b + 2 - 1] = 2
	elif b == 2:
		board[a - 2 - 1][b - 1 - 1] = 2
		board[a + 2 - 1][b + 1 - 1] = 2
	elif b == 7:
		board[a - 2 - 1][b + 1 - 1] = 2
		board[a + 2 - 1][b - 1 - 1] = 2
	else:
		board[a - 1 - 1][b - 2 - 1] = 2
		board[a + 1 - 1][b + 2 - 1] = 2
	for i in range(len(board)):
		print(*board[i])


def func():
	(a, b) = map(int, input().split())
	l = []
	for i in range(8):
		temp = []
		for j in range(8):
			temp.append(0)
		l.append(temp)
	l[a - 1][b - 1] = 1
	if a == 1 and b == 1:
		l[1][2] = 2
	elif a == 1 and b == 8:
		l[1][5] = 2
	elif a == 8 and b == 1:
		l[5][1] = 2
	elif a == 8 and b == 8:
		l[5][6] = 2
	elif a == 1:
		l[2][b - 2] = 2
		l[2][b] = 2
	elif b == 1:
		l[a][2] = 2
		l[a - 2][2] = 2
	elif b == 8:
		l[a][5] = 2
		l[a - 2][5] = 2
	elif a == 8:
		l[5][b - 2] = 2
		l[5][b] = 2
	elif a == 2 and b == 2:
		l[0][4] = 2
		l[3][0] = 2
	elif a == 2 and b == 7:
		l[0][3] = 2
		l[3][7] = 2
	elif a == 7 and b == 2:
		l[4][0] = 2
		l[7][4] = 2
	elif a == 7 and b == 7:
		l[7][3] = 2
		l[4][7] = 2
	elif b == 2 or b == 7:
		l[a - 3][b - 2] = 2
		l[a + 1][b] = 2
	else:
		l[a - 2][b + 1] = 2
		l[a][b - 3] = 2
	for i in range(len(l)):
		print(*l[i])
t = int(input())
while t:
	func()
	t -= 1


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	ans = [[0 for i in range(8)] for j in range(8)]
	ans[x][y] = 1
	a = [[0, 0], [0, 7], [7, 0], [7, 7]]
	b = [[-2, -1], [-2, +1], [-1, -2], [-1, +2], [+1, -2], [+1, +2], [+2, -1], [+2, +1]]
	if [x, y] in a:
		for i in range(len(b)):
			if 0 <= x + b[i][0] <= 7 and 0 <= y + b[i][1] <= 7:
				ans[x + b[i][0]][y + b[i][1]] = 2
				break
	elif x == 0:
		ans[x + 2][y - 1] = 2
		ans[x + 2][y + 1] = 2
	elif x == 7:
		ans[x - 2][y - 1] = 2
		ans[x - 2][y + 1] = 2
	elif y == 0:
		ans[x + 1][y + 2] = 2
		ans[x - 1][y + 2] = 2
	elif y == 7:
		ans[x + 1][y - 2] = 2
		ans[x - 1][y - 2] = 2
	elif x == 1 and y == 1:
		ans[x + 2][y - 1] = 2
		ans[x - 1][y + 3] = 2
	elif x == 1 and y == 6:
		ans[x - 1][y - 3] = 2
		ans[x + 2][y + 1] = 2
	elif x == 6 and y == 1:
		ans[x - 2][y - 1] = 2
		ans[x + 1][y + 3] = 2
	elif x == 6 and y == 6:
		ans[x - 2][y + 1] = 2
		ans[x + 1][y - 3] = 2
	elif y == 1 or y == 6:
		ans[x - 2][y + 1] = 2
		ans[x + 2][y - 1] = 2
	elif x == 1 or x == 6:
		ans[x - 1][y - 2] = 2
		ans[x + 1][y + 2] = 2
	else:
		ans[x - 1][y - 2] = 2
		ans[x + 1][y + 2] = 2
	for i in range(8):
		print(*ans[i])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ans = []
	for i in range(8):
		ans.append([0] * 8)
	ans[x - 1][y - 1] = 1
	if x == 1:
		if y == 1:
			ans[2][1] = 2
		elif y == 8:
			ans[2][6] = 2
		else:
			ans[2][y] = 2
			ans[2][y - 2] = 2
	elif x == 8:
		if y == 1:
			ans[5][1] = 2
		elif y == 8:
			ans[5][6] = 2
		else:
			ans[5][y - 2] = 2
			ans[5][y] = 2
	elif y == 1:
		ans[x - 2][2] = 2
		ans[x][2] = 2
	elif y == 8:
		ans[x - 2][5] = 2
		ans[x][5] = 2
	elif y == 2:
		if x == 2:
			ans[3][0] = 2
			ans[0][4] = 2
		elif x == 7:
			ans[3][0] = 2
			ans[7][3] = 2
		else:
			ans[x + 1][y - 2] = 2
			ans[x - 3][y] = 2
	elif y == 7:
		if x == 2:
			ans[3][7] = 2
			ans[0][3] = 2
		elif x == 7:
			ans[4][7] = 2
			ans[7][3] = 2
		else:
			ans[x + 1][y - 2] = 2
			ans[x - 3][y] = 2
	else:
		ans[x][y - 3] = 2
		ans[x - 2][y + 1] = 2
	for i in range(8):
		print(*ans[i])


for i in range(1, 1000):
	pass
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(x1, y1) = (0, 0)
	(x2, y2) = (0, 0)
	(x3, y3) = (-1, -1)
	x1 = x - 2
	x2 = x + 2
	y1 = y - 1
	y2 = y + 1
	if x == 2:
		x1 = x - 1
		x2 = x + 1
		y1 = y - 2
		y2 = y + 2
	if y == 2:
		x2 = x - 2
		y2 = y - 1
		x1 = x + 2
		y1 = y + 1
	if x == 7:
		x1 = x - 1
		x2 = x + 1
		y1 = y - 2
		y2 = y + 2
	if x == 2 and y == 2:
		(x1, y1) = (1, 4)
		(x2, y2) = (5, 1)
	if x == 7 and y == 7:
		(x1, y1) = (8, 5)
		(x2, y2) = (4, 8)
	if x == 2 and y == 7:
		(x1, y1) = (1, 5)
		(x2, y2) = (5, 8)
	if x == 7 and y == 2:
		(x1, y1) = (4, 1)
		(x2, y2) = (8, 4)
	if x == 1:
		x1 = x2 = x + 2
	if x == 8:
		x1 = x2 = x - 2
	if y == 1:
		y1 = y2 = y + 2
		x1 = x - 1
		x2 = x + 1
	if y == 8:
		y1 = y2 = y - 2
		x1 = x - 1
		x2 = x + 1
	for i in range(1, 1000):
		pass
	ar = []
	for i in range(1, 9):
		row = []
		for j in range(1, 9):
			if i == x1 and j == y1:
				row.append(2)
			elif i == x2 and j == y2:
				row.append(2)
			elif i == x and j == y:
				row.append(1)
			else:
				row.append(0)
		ar.append(row)
	for i in range(1, 1000):
		pass
	for i in ar:
		print(*i)


t = int(input())
for _ in range(t):
	arr = [[0 for i in range(8)] for j in range(8)]
	(A, B) = map(int, input().split())
	x1 = 0
	y1 = 0
	x2 = 0
	y2 = 0
	if A == 1 and B == 1:
		arr[0][0] = 1
		arr[2][1] = 2
	elif A == 1 and B == 8:
		arr[0][7] = 1
		arr[2][6] = 2
	elif A == 8 and B == 8:
		arr[7][7] = 1
		arr[5][6] = 2
	elif A == 8 and B == 1:
		arr[7][0] = 1
		arr[5][1] = 2
	elif B == 1:
		arr[A - 1][0] = 1
		arr[A - 2][B + 1] = 2
		arr[A][B + 1] = 2
	elif B == 8:
		arr[A - 1][7] = 1
		arr[A - 2][5] = 2
		arr[A][5] = 2
	elif A == 8:
		arr[7][B - 1] = 1
		arr[5][B - 2] = 2
		arr[5][B] = 2
	elif A == 1:
		arr[0][B - 1] = 1
		arr[2][B - 2] = 2
		arr[2][B] = 2
	elif B <= 5 and A <= 6:
		arr[A - 1][B - 1] = 1
		arr[A - 2][B + 2] = 2
		arr[A + 1][B - 2] = 2
	elif B > 5 and A <= 6:
		arr[A - 1][B - 1] = 1
		arr[A - 2][B - 4] = 2
		arr[A + 1][B] = 2
	elif B <= 5 and A == 7:
		arr[A - 1][B - 1] = 1
		arr[A][B + 2] = 2
		arr[A - 3][B - 2] = 2
	elif B > 5 and A == 7:
		arr[A - 1][B - 1] = 1
		arr[A][B - 4] = 2
		arr[A - 3][B] = 2
	print(*arr[0])
	print(*arr[1])
	print(*arr[2])
	print(*arr[3])
	print(*arr[4])
	print(*arr[5])
	print(*arr[6])
	print(*arr[7])


for i in range(int(input())):
	(n, m) = map(int, input().split())
	if n == 1 and m == 1:
		xx = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 1 and m == 2:
		xx = [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 1 and m == 3:
		xx = [[0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 1 and m == 4:
		xx = [[0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 1 and m == 5:
		xx = [[0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 1 and m == 6:
		xx = [[0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 1 and m == 7:
		xx = [[0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 1 and m == 8:
		xx = [[0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 2 and m == 1:
		xx = [[0, 0, 2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 2 and m == 2:
		xx = [[0, 0, 0, 0, 2, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 2 and m == 3:
		xx = [[2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 2 and m == 4:
		xx = [[0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 2 and m == 5:
		xx = [[0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 2 and m == 6:
		xx = [[0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 2 and m == 7:
		xx = [[0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 2 and m == 8:
		xx = [[0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 3 and m == 1:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 3 and m == 2:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 3 and m == 3:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 3 and m == 4:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 3 and m == 5:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 3 and m == 6:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 3 and m == 7:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 3 and m == 8:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 4 and m == 1:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 4 and m == 2:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 4 and m == 3:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 4 and m == 4:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 4 and m == 5:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 4 and m == 6:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 4 and m == 7:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 4 and m == 8:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 5 and m == 1:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 5 and m == 2:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 5 and m == 3:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 5 and m == 4:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 5 and m == 5:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 5 and m == 6:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 5 and m == 7:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 5 and m == 8:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 6 and m == 1:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 6 and m == 2:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 6 and m == 3:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 6 and m == 4:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 6 and m == 5:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 6 and m == 6:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0]]
	if n == 6 and m == 7:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2]]
	if n == 6 and m == 8:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0]]
	if n == 7 and m == 1:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0]]
	if n == 7 and m == 2:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0]]
	if n == 7 and m == 3:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0]]
	if n == 7 and m == 4:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0]]
	if n == 7 and m == 5:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0]]
	if n == 7 and m == 6:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2]]
	if n == 7 and m == 7:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 2, 0, 0, 0]]
	if n == 7 and m == 8:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 2, 0, 0]]
	if n == 8 and m == 1:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0]]
	if n == 8 and m == 2:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0]]
	if n == 8 and m == 3:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0]]
	if n == 8 and m == 4:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0]]
	if n == 8 and m == 5:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0]]
	if n == 8 and m == 6:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0]]
	if n == 8 and m == 7:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0]]
	if n == 8 and m == 8:
		xx = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]]
	for j in xx:
		print(*j)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	cboard = [[0 for i in range(8)] for j in range(8)]
	cboard[a - 1][b - 1] = 1
	if a == 2 and b == 2:
		cboard[3][0] = 2
		cboard[0][4] = 2
	elif a == 2 and b == 7:
		cboard[3][7] = 2
		cboard[0][3] = 2
	elif a == 7 and b == 2:
		cboard[4][0] = 2
		cboard[7][4] = 2
	elif a == 7 and b == 7:
		cboard[4][7] = 2
		cboard[7][3] = 2
	elif a == 1 and b == 1:
		cboard[2][1] = 2
	elif a == 8 and b == 1:
		cboard[-3][1] = 2
	elif a == 8 and b == 8:
		cboard[-3][-2] = 2
	elif a == 1 and b == 8:
		cboard[2][-2] = 2
	elif a == 1:
		cboard[2][b] = 2
		cboard[2][b - 2] = 2
	elif a == 8:
		cboard[-3][b] = 2
		cboard[-3][b - 2] = 2
	elif b == 1:
		cboard[a][2] = 2
		cboard[a - 2][2] = 2
	elif b == 8:
		cboard[a][-3] = 2
		cboard[a - 2][-3] = 2
	elif a + 1 < 8 and a - 3 >= 0:
		cboard[a + 1][b] = 2
		cboard[a - 3][b - 2] = 2
	else:
		cboard[a][b + 1] = 2
		cboard[a - 2][b - 3] = 2
	for row in cboard:
		print(*row)


I = lambda : list(map(int, input().split()))
(t,) = I()
for i in range(t):
	(a, b) = I()
	op = [[-2, -1], [2, 1], [2, -1], [-2, 1]]
	rop = [[1, 2], [-1, -2], [1, -2], [-1, 2]]
	chess = [[0] * 8 for i in range(8)]
	chess[a - 1][b - 1] = 1
	pos = 0
	ix = 0
	vis = set()
	for (dy, dx) in [[-1, -1], [-1, 1], [1, -1], [1, 1], [0, 1], [0, -1], [1, 0], [-1, 0]]:
		(x, y) = (a + dx, b + dy)
		if x >= 1 and y >= 1 and (x <= 8) and (y <= 8):
			vis.add((x, y))
	noice = set(vis)
	ans = []
	for (dy, dx) in op + rop if 1 not in [x, y] else rop + op:
		(x, y) = (a + dx, b + dy)
		if x >= 1 and y >= 1 and (x <= 8) and (y <= 8):
			cs = len(vis)
			new = set(vis)
			for i in vis:
				(mx, my) = i
				if mx == x or my == y or x + y == mx + my or (x - y == mx - my):
					new.remove(i)
			if len(new) < cs:
				ans.append((x, y))
				vis = set(new)
	if len(ans) == 3:
		na = []
		for i in ans:
			(x, y) = (i[1], i[0])
			if i == (4, 1):
				(x, y) = (1, 5)
			elif i == (1, 5):
				(x, y) = (5, 8)
			if i == (5, 1):
				(x, y) = (8, 5)
			elif i == (8, 5):
				(x, y) = (4, 8)
			if x >= 1 and y >= 1 and (x <= 8) and (y <= 8) and ([x, y] != [i[1], i[0]]):
				na.append((x, y))
				na.append(i)
				break
		ans = na
		if not ans:
			vis = set(noice)
			for (dy, dx) in rop:
				(x, y) = (a + dx, b + dy)
				if x >= 1 and y >= 1 and (x <= 8) and (y <= 8):
					cs = len(vis)
					new = set(vis)
					for i in vis:
						(mx, my) = i
						if mx == x or my == y or x + y == mx + my or (x - y == mx - my):
							new.remove(i)
					if len(new) < cs:
						ans.append((x, y))
						vis = set(new)
	for (x, y) in ans:
		chess[x - 1][y - 1] = 2
	for i in chess:
		print(*i)


import math
import itertools
import heapq
from math import floor, ceil
from collections import deque
import sys
from collections import Counter
I = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7

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

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

def isSubsequence(s, t):
	for i in range(0, len(s)):
		try:
			index = t.index(s[i])
		except ValueError:
			return False
		t = t[index + 1:]
	return True

def bisect_right(a, x):
	(lo, hi) = (0, len(a))
	while lo < hi:
		mid = lo + (hi - lo) // 2
		if a[mid] > x:
			hi = mid
		else:
			lo = mid + 1
	return lo

def bisect_left(a, x):
	(lo, hi) = (0, len(a))
	while lo < hi:
		mid = lo + (hi - lo) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def binary_search(nums, target):
	(left, right) = (0, len(nums) - 1)
	while left <= right:
		pivot = left + (right - left) // 2
		if nums[pivot] == target:
			return pivot
		if target < nums[pivot]:
			right = pivot - 1
		else:
			left = pivot + 1
	return -1

def prefixSum(arr):
	dp = [arr[0]]
	arrLen = len(arr)
	for i in range(1, arrLen):
		dp.append(dp[-1] + arr[i])
	return dp

def suffixSum(arr):
	arrLen = len(arr)
	dp = [0] * arrLen
	dp[-1] = arr[-1]
	for i in range(N - 2, -1, -1):
		dp[i] = dp[i + 1] + arr[i]
	return dp

def fun():
	return

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)

def solve():
	(i, j) = M()
	mat = []
	for x in range(8):
		tmp = []
		for y in range(8):
			tmp.append(0)
		mat.append(tmp)
	i -= 1
	j -= 1
	coveredrow = set()
	coveredcol = set()
	mat[i][j] = 1
	c = 0
	if i == 0 and j == 0:
		mat[i + 1][j + 2] = 2
	elif i == 0 and j == 7:
		mat[i + 1][j - 2] = 2
	elif i == 7 and j == 0:
		mat[i - 1][j + 2] = 2
	elif i == 7 and j == 7:
		mat[i - 1][j - 2] = 2
	elif i == 0:
		mat[i + 2][j - 1] = 2
		mat[i + 2][j + 1] = 2
	elif i == 7:
		mat[i - 2][j - 1] = 2
		mat[i - 2][j + 1] = 2
	elif j == 0:
		mat[i + 1][j + 2] = 2
		mat[i - 1][j + 2] = 2
	elif j == 7:
		mat[i + 1][j - 2] = 2
		mat[i - 1][j - 2] = 2
	else:
		poss = [[(i + 1, j - 2), (i - 3, j + 1)], [(i + 1, j + 2), (i - 3, j - 1)], [(i - 1, j + 2), (i + 3, j - 1)], [(i - 1, j - 2), (i + 3, j + 1)]]
		for X in poss:
			(r1, c1) = (X[0][0], X[0][1])
			(r2, c2) = (X[1][0], X[1][1])
			if 0 <= r1 <= 7 and 0 <= r2 <= 7 and (0 <= c1 <= 7) and (0 <= c2 <= 7):
				mat[r1][c1] = 2
				mat[r2][c2] = 2
				break
	for x in range(8):
		print(' '.join([str(i) for i in mat[x]]))
TC = 1
TC = int(input())
for testcases in range(TC):
	solve()


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

	def retx(ret, x, y):
		if x > 1 and x < 6 and (y > 1) and (y < 6):
			ret[x - 1][y - 2] = 2
			ret[x + 1][y + 2] = 2
		if x == 0:
			if y == 0:
				ret[2][1] = 2
			elif y == 7:
				ret[2][6] = 2
			else:
				ret[2][y - 1] = 2
				ret[2][y + 1] = 2
			return ret
		if x == 7:
			if y == 0:
				ret[5][1] = 2
			elif y == 7:
				ret[5][6] = 2
			else:
				ret[5][y - 1] = 2
				ret[5][y + 1] = 2
			return ret
		if y == 0:
			ret[x - 1][2] = 2
			ret[x + 1][2] = 2
			return ret
		if y == 7:
			ret[x - 1][5] = 2
			ret[x + 1][5] = 2
			return ret
		if x == 1:
			if y == 1:
				ret[3][0] = 2
				ret[0][4] = 2
			elif y == 6:
				ret[3][7] = 2
				ret[0][3] = 2
			else:
				ret[x - 1][y - 2] = 2
				ret[x + 1][y + 2] = 2
			return ret
		if x == 6:
			if y == 1:
				ret[4][0] = 2
				ret[7][4] = 2
			elif y == 6:
				ret[4][7] = 2
				ret[7][3] = 2
			else:
				ret[x - 1][y - 2] = 2
				ret[x + 1][y + 2] = 2
			return ret
		if y == 6:
			ret[x - 2][7] = 2
			ret[x + 2][5] = 2
		elif y == 1:
			ret[x - 2][0] = 2
			ret[x + 2][2] = 2
		return ret
	(x, y) = map(int, input().split())
	(x, y) = (x - 1, y - 1)
	rett = [[0 for i in range(8)] for j in range(8)]
	rett[x][y] = 1
	rett = retx(rett, x, y)
	for i in rett:
		print(' '.join(map(str, i)))