You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.

The picture showing the correct sudoku solution:

[Image]

Blocks are bordered with bold black color.

Your task is to change at most $9$ elements of this field (i.e. choose some $1 \le i, j \le 9$ and change the number at the position $(i, j)$ to any other number in range $[1; 9]$) to make it anti-sudoku. The anti-sudoku is the $9 \times 9$ field, in which:  Any number in this field is in range $[1; 9]$;  each row contains at least two equal elements;  each column contains at least two equal elements;  each $3 \times 3$ block (you can read what is the block in the link above) contains at least two equal elements. 

It is guaranteed that the answer exists.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

Each test case consists of $9$ lines, each line consists of $9$ characters from $1$ to $9$ without any whitespaces — the correct solution of the sudoku puzzle.


-----Output-----

For each test case, print the answer — the initial field with at most $9$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.


-----Example-----
Input
1
154873296
386592714
729641835
863725149
975314628
412968357
631457982
598236471
247189563

Output
154873396
336592714
729645835
863725145
979314628
412958357
631457992
998236471
247789563

Difficulty: EASY
Tags: Implementation

Constructive algorithms

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	l = []
	for i in range(9):
		l.append(input())
	l = [[int(j) for j in l[i]] for i in range(9)]
	l = [[j if j != 2 else 1 for j in l[i]] for i in range(9)]
	for i in l:
		for j in i:
			print(j, end='')
		print()


t = int(input())
while t:
	for i in range(9):
		line = input()
		print(line.replace('1', '2'))
	t = t - 1


import os
import sys
from math import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def array():
	return [int(i) for i in input().split()]
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def c(a):
	if a == 9:
		return 1
	else:
		return a + 1
for _ in range(int(input())):
	m = []
	for i in range(9):
		m.append([int(i) for i in input()])
	m[0][0] = c(m[0][0])
	m[1][3] = c(m[1][3])
	m[2][6] = c(m[2][6])
	m[3][1] = c(m[3][1])
	m[4][4] = c(m[4][4])
	m[5][7] = c(m[5][7])
	m[6][2] = c(m[6][2])
	m[7][5] = c(m[7][5])
	m[8][8] = c(m[8][8])
	for i in m:
		for j in i:
			print(j, end='')
		print()


t = int(input())
for _ in range(t):
	for __ in range(9):
		print(input().replace('2', '1'))


T = int(input())
for i in range(T):
	puzzle = [input() for _ in range(9)]
	A = [0, 1, 2, 3, 4, 5, 6, 7, 8]
	B = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for (a, b) in zip(A, B):
		tmp = int(puzzle[a][b])
		if tmp == 9:
			tmp = 1
		else:
			tmp += 1
		tmp = str(tmp)
		puzzle[a] = puzzle[a][0:b] + tmp + puzzle[a][b + 1:9]
	for j in range(9):
		print(puzzle[j])


for _ in range(int(input())):
	a = [list(input())]
	ind = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(8):
		temp = list(input())
		a[-1][ind[i]] = temp[ind[i]]
		a.append(temp)
	a[-1][8] = a[-2][8]
	for el in a:
		print(''.join(el))


for _ in range(int(input())):
	ll = []
	for i in range(9):
		ll.append(list(input()))
	for i in range(9):
		for j in range(9):
			if ll[i][j] == str(2):
				ll[i][j] = str(3)
	for i in ll:
		print(''.join(i))


a = int(input())

def getN(n):
	if n == 9:
		return 8
	else:
		return n + 1
for i in range(0, a):
	arr = []
	sol = []
	for i in range(0, 9):
		arr.append(input())
	for i in range(0, 9):
		print(arr[i][:i % 3 * 3 + i // 3] + str(getN(int(arr[i][i % 3 * 3 + i // 3]))) + arr[i][i % 3 * 3 + i // 3 + 1:])


for _ in range(int(input())):
	for i in range(9):
		print(input().replace('9', '8'))


from math import *
from itertools import *
from collections import *

def ii():
	return int(input())

def mas():
	return [int(i) for i in input().split()]
INF = 1000000000.0 + 1
t = 0

def solve():
	sudoku = [[] for i in range(9)]
	for i in range(9):
		s = input()
		for j in range(9):
			sudoku[i].append(s[j])
	sudoku[0][0] = sudoku[0][1]
	sudoku[1][7] = sudoku[1][8]
	sudoku[2][3] = sudoku[2][4]
	sudoku[3][2] = sudoku[3][1]
	sudoku[4][4] = sudoku[4][5]
	sudoku[5][8] = sudoku[5][7]
	sudoku[6][1] = sudoku[6][2]
	sudoku[7][5] = sudoku[6][5]
	sudoku[7][5] = sudoku[6][5]
	sudoku[8][6] = sudoku[7][6]
	for i in range(9):
		print(*sudoku[i], sep='')

def main():
	t = int(input())
	while t:
		solve()
		t -= 1
main()


for _ in range(int(input())):
	s = []
	k = 0
	for i in range(9):
		s.append(list(input()))
	i = 0
	while i < 8:
		for j in range(k, 9, 3):
			s[i][j] = str(int(s[i][j]) + 1)
			if int(s[i][j]) == 10:
				s[i][j] = '1'
			i += 1
		k += 1
	for i in range(9):
		print(''.join(s[i]))


for _ in range(int(input())):
	board = []
	for _ in range(9):
		row = [num for num in input()]
		board.append(row)
	for (r, c) in [(0, 0), (1, 4), (2, 8), (3, 1), (4, 5), (5, 6), (6, 2), (7, 3), (8, 7)]:
		val = int(board[r][c])
		board[r][c] = str(val + 1) if val < 9 else str(1)
	for row in board:
		print(''.join(row))


test = int(input())
while test != 0:
	a = []
	for i in range(9):
		arr = list(map(int, input().split()))
		a.append(arr)
	for i in range(9):
		x = str(*a[i])
		for j in range(9):
			if x[j] == '2':
				x = x[:j] + '1' + x[j + 1:]
				a[i] = x
				break
	for i in range(9):
		print(*a[i], sep='')
	test -= 1


for _ in range(int(input())):
	for i in range(9):
		row = input().replace('1', '2')
		print(row)


import string
l = [0, 3, 6, 1, 4, 7, 2, 5, 8]
t = int(input())
for _ in range(t):
	for i in range(9):
		row = input()
		pos = l[i]
		el = int(row[pos]) % 9 + 1
		print('{}{}{}'.format(row[:pos], str(el), row[pos + 1:]))


for ii in range(int(input())):
	for i in range(9):
		s = list(input())
		for j in range(9):
			if s[j] == '3':
				print('1', end='')
			else:
				print(s[j], end='')
		print()


from collections import defaultdict

def solve(grid):
	for i in range(1, 10):
		for j in range(9):
			if grid[i][j] == 4:
				grid[i][j] = 2
t = int(input())
for _ in range(t):
	grid = defaultdict(list)
	for i in range(1, 10):
		grid[i] = list(map(int, input()))
	solve(grid)
	for i in range(1, 10):
		print(*grid[i], sep='')


from collections import defaultdict
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(iinput()):
	mat = []
	ans = []
	for i in range(9):
		mat.append(list(input()))
		ans.append(mat[i])
	for i in range(9):
		k = i % 3
		j = k * 3 + i // 3
		ans[i][j] = list(set([chr(ord('1') + i) for i in range(9)]) - set([mat[i][j]]))[0]
	for i in ans:
		print(''.join(i))


t = int(input())
for i in range(t):
	A = []
	for j in range(9):
		B = [int(j) for j in input()]
		A.append(B)
	k = 0
	p = 0
	for j in range(9):
		if k == 8:
			A[j][k] = A[j][0]
		else:
			A[j][k] = A[j][k + 1]
		k += 3
		if k >= 9:
			p += 1
			k = p
	for j in A:
		for k in j:
			print(k, end='')
		print()


t = int(input())
while t != 0:
	t -= 1
	mat = []
	for _ in range(9):
		mat.append([int(x) for x in input()])
	change = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for point in change:
		mat[point[0]][point[1]] = mat[point[0]][point[1]] + 1
		if mat[point[0]][point[1]] == 10:
			mat[point[0]][point[1]] %= 9
	for i in range(9):
		print(''.join([str(x) for x in mat[i]]))


t = int(input())
for ooo in range(t):
	for i in range(9):
		r = input()
		m = (i * 3 + 1) % 9 - 1 + i // 3
		k = r[m]
		if k == '9':
			print(r[:m] + '1' + r[m + 1:])
		else:
			print(r[:m] + str(int(k) + 1) + r[m + 1:])


test_cases = int(input())
while test_cases:
	sudoku = []
	for i in range(9):
		j = input()
		r = j.find('2')
		j = j[:r] + '1' + j[r + 1:]
		print(j)
	test_cases = test_cases - 1


t = int(input())
for _ in range(t):
	a = []
	for i in range(9):
		a.append(list(input()))
	a[0][0] = a[1][0]
	a[3][1] = a[4][1]
	a[6][2] = a[7][2]
	a[1][3] = a[2][3]
	a[4][4] = a[5][4]
	a[7][5] = a[8][5]
	a[2][6] = a[1][6]
	a[5][7] = a[4][7]
	a[8][8] = a[7][8]
	for i in range(9):
		print(*a[i], sep='')


t = int(input())
for i in range(t):
	l = []
	for i in range(0, 9):
		l2 = []
		s = input()
		for k in s:
			l2.append(int(k))
		l.append(l2)
	l[1 - 1][7 - 1] += 1
	l[2 - 1][2 - 1] += 1
	l[3 - 1][6 - 1] += 1
	l[4 - 1][9 - 1] += 1
	l[5 - 1][3 - 1] += 1
	l[6 - 1][5 - 1] += 1
	l[7 - 1][8 - 1] += 1
	l[8 - 1][1 - 1] += 1
	l[9 - 1][4 - 1] += 1
	for i in range(0, 9):
		s = ''
		for j in range(0, 9):
			if int(l[i][j]) == 10:
				l[i][j] = str('1')
			s = s + str(l[i][j])
		print(s)


number_test = int(input())
for k in range(number_test):
	for i in range(9):
		ligne = list(map(int, input()))
		b = False
		for j in range(9):
			if ligne[j] == 1 and (not b):
				if j % 3 == 0:
					ligne[j + 1] = 1
					b = True
				elif j % 3 == 1:
					ligne[j + 1] = 1
					b = True
				else:
					ligne[j - 2] = 1
					b = True
		ligne_envoi = ''.join(map(str, ligne))
		print(ligne_envoi)


def c(i, j):
	l[i][j] += 1
	if l[i][j] == 10:
		l[i][j] = 1
for _ in range(int(input())):
	l = [list(map(int, list(input()))) for i in range(9)]
	j = 0
	for i in range(0, 9, 3):
		c(i, j)
		c(i + 1, j + 3)
		c(i + 2, j + 6)
		j += 1
	for i in range(9):
		print(''.join(map(str, l[i])))


for _ in range(int(input())):
	l = []
	for i in range(9):
		l.append(list(map(int, list(input()))))
	l[0][0] = (l[0][0] + 1) % 9 + 1
	l[1][3] = (l[1][3] + 1) % 9 + 1
	l[2][6] = (l[2][6] + 1) % 9 + 1
	l[3][1] = (l[3][1] + 1) % 9 + 1
	l[4][4] = (l[4][4] + 1) % 9 + 1
	l[5][7] = (l[5][7] + 1) % 9 + 1
	l[6][2] = (l[6][2] + 1) % 9 + 1
	l[7][5] = (l[7][5] + 1) % 9 + 1
	l[8][8] = (l[8][8] + 1) % 9 + 1
	for i in l:
		for j in i:
			print(j, end='')
		print()


for _ in range(int(input())):
	l1 = []
	for i in range(9):
		l1.append(list(input()))
		l1[i][l1[i].index('2')] = '1'
	for item in l1:
		for i in item:
			print(i, end='')
		print()


TC = int(input())
for __ in range(TC):
	a = []
	for i in range(9):
		a.append(input())
	for i in range(9):
		j = i // 3 + i % 3 * 3
		a[i] = a[i][:j] + ('2' if a[i][j] == '1' else '1') + a[i][j + 1:]
	print('\n'.join((x for x in a)))


for _ in range(int(input()) * 9):
	print(input().replace('1', '2'))


t = int(input())
for i in range(t):
	a = []
	x = [0, 9, 8, 7, 6, 6, 4, 3, 2, 1]
	for j in range(9):
		b = input()
		a.append(list(map(int, list(b))))
	a[0][0] = x[a[0][0]]
	a[1][4] = x[a[1][4]]
	a[2][8] = x[a[2][8]]
	a[3][1] = x[a[3][1]]
	a[4][5] = x[a[4][5]]
	a[5][6] = x[a[5][6]]
	a[6][2] = x[a[6][2]]
	a[7][3] = x[a[7][3]]
	a[8][7] = x[a[8][7]]
	for j in range(9):
		print(''.join(map(str, a[j])))


import sys
input = sys.stdin.readline
for tt in range(int(input())):
	l = []
	for i in range(9):
		temp = [int(i) for i in input()[:-1]]
		l.append(temp)
	l[0][6] = l[0][6] + 1 if l[0][6] != 9 else 1
	l[1][1] = l[1][1] + 1 if l[1][1] != 9 else 1
	l[2][5] = l[2][5] + 1 if l[2][5] != 9 else 1
	l[3][8] = l[3][8] + 1 if l[3][8] != 9 else 1
	l[4][2] = l[4][2] + 1 if l[4][2] != 9 else 1
	l[5][4] = l[5][4] + 1 if l[5][4] != 9 else 1
	l[6][7] = l[6][7] + 1 if l[6][7] != 9 else 1
	l[7][0] = l[7][0] + 1 if l[7][0] != 9 else 1
	l[8][3] = l[8][3] + 1 if l[8][3] != 9 else 1
	for i in range(9):
		print(*l[i], sep='')


t = int(input())
for _ in range(t):
	L = []
	for u in range(9):
		a = list(input())
		L.append(a)
	L[0][0] = L[0][1]
	L[1][3] = L[1][4]
	L[2][6] = L[2][7]
	L[3][1] = L[3][2]
	L[4][4] = L[4][5]
	L[5][7] = L[5][8]
	L[6][2] = L[6][0]
	L[7][5] = L[7][3]
	L[8][8] = L[8][6]
	for h in range(9):
		print(''.join(L[h]))


from sys import stdin, stdout
t = int(stdin.readline())
while t > 0:
	a = []
	for i in range(9):
		x = stdin.readline().split('\n')[0]
		temp = []
		for i in range(9):
			temp.append(x[i])
		a.append(temp)
	for i in range(9):
		for j in range(9):
			if a[i][j] == '9':
				a[i][j] = '1'
	for i in range(9):
		stdout.write('{}\n'.format(''.join(a[i])))
	t -= 1


def main():
	test = int(input())
	for t in range(test):
		matrix = []
		for i in range(9):
			l = [int(i) for i in input()]
			matrix.append(l)
		matrix[0][0] = matrix[0][1]
		matrix[1][3] = matrix[1][4]
		matrix[2][6] = matrix[2][7]
		matrix[3][1] = matrix[3][2]
		matrix[4][4] = matrix[4][5]
		matrix[5][7] = matrix[5][8]
		matrix[6][2] = matrix[6][0]
		matrix[7][5] = matrix[7][3]
		matrix[8][8] = matrix[8][6]
		for i in range(9):
			for j in range(9):
				print(matrix[i][j], end='')
			print()
main()


for _ in range(int(input())):
	ans = []
	for i in range(3):
		for j in range(3):
			a = input()
			a = list(a)
			if int(a[3 * j + i]) == 5:
				a[3 * j + i] = '1'
			else:
				a[3 * j + i] = '5'
			ans.append(''.join(a))
	for i in range(9):
		print(ans[i])


from sys import stdin
from collections import Counter
input = stdin.buffer.readline
T = int(input())
for _ in range(T):
	sd = []
	for _ in range(9):
		(t, ls) = (int(input()), [])
		for _ in range(9):
			ls.append(t % 10)
			t //= 10
		sd.append(list(reversed(ls)))
	p = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for (a, b) in p:
		sd[a][b] = (sd[a][b] - 1 + 1) % 9 + 1
	for i in range(9):
		print(''.join(map(str, sd[i])))


t = int(input())
for _ in range(t):
	mat = []
	for i in range(9):
		arr = list(map(int, input()))
		mat.append(arr)
	req = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for i in req:
		(a, b) = (i[0], i[1])
		if mat[a][b] != 9:
			mat[a][b] = 9
		else:
			mat[a][b] = 1
	for i in mat:
		listToStr = ''.join(map(str, i))
		print(listToStr)


t = int(input())
for g in range(t):
	matrix = [[int(j) for j in list(input())] for i in range(9)]
	ind = 0
	for i in range(0, 9, 3):
		matrix[i][ind] = matrix[i + 1][ind]
		ind += 1
	ind = 3
	for i in range(1, 9, 3):
		matrix[i][ind] = matrix[i + 1][ind]
		ind += 1
	ind = 6
	for i in range(2, 9, 3):
		matrix[i][ind] = matrix[i - 1][ind]
		ind += 1
	[print(''.join([str(j) for j in i])) for i in matrix]


t = int(input())
mc = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
for __ in range(t):
	matrix = []
	for j in range(9):
		a = list(map(int, input()))
		matrix.append(a)
	for l in mc:
		if matrix[l[0]][l[1]] == 9:
			matrix[l[0]][l[1]] = 1
		else:
			matrix[l[0]][l[1]] += 1
	for i in range(9):
		curr = matrix[i]
		s = ''
		for i in curr:
			s += str(i)
		print(s)


t = int(input())
for _ in range(t):
	l = []
	for _ in range(9):
		l.append(list(input()))
	for i in range(9):
		for j in range(9):
			if l[i][j] == '4':
				l[i][j] = '3'
				break
	for i in l:
		print(''.join(i))


def anti_sudoku(arr):
	for i in range(3):
		for j in range(3):
			v = arr[i * 3 + j][j * 3 + i]
			if v == 9:
				v -= 1
			else:
				v += 1
			arr[i * 3 + j][j * 3 + i] = v
	for row in arr:
		print(''.join([str(el) for el in row]))

def read():
	sudoku = []
	for i in range(9):
		row = input()
		row = [int(el) for el in row]
		sudoku.append(row)
	return sudoku
tests = int(input())
sudokus = [read() for _ in range(tests)]
[anti_sudoku(arr) for arr in sudokus]


for t in range(int(input())):
	sudoku = []
	for i in range(9):
		sudoku.append([int(x) for x in input()])
	i = [0, 1, 2, 3, 4, 5, 6, 7, 8]
	j = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for x in range(9):
		for change in range(1, 10):
			if sudoku[i[x]][j[x]] != change:
				sudoku[i[x]][j[x]] = change
				break
	for line in sudoku:
		print(*(c for c in line), sep='')


import sys
import math
mod = 998244353

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
t = int(input())
for _ in range(t):
	d = {}
	for i in range(9):
		d[i] = []
		s = ''
		s = input()
		for j in range(9):
			d[i].append(s[j])
	d[1][1] = d[1][0]
	d[2][5] = d[1][3]
	d[0][6] = d[0][5]
	d[4][2] = d[4][0]
	d[5][4] = d[3][5]
	d[3][8] = d[5][7]
	d[7][0] = d[7][1]
	d[8][3] = d[6][5]
	d[6][7] = d[6][6]
	for i in range(9):
		for j in range(9):
			print(d[i][j], end='')
		print()


q = int(input())
for _ in range(q):
	b = []
	for k in range(9):
		b.append([int(x) for x in input()])
	u = set()
	b[0][0] = b[0][1]
	u.add(b[0][1])
	for k in range(1, 10):
		if k not in u and b[1][3] != k:
			b[1][3] = k
			u.add(k)
			break
	for k in range(1, 10):
		if k not in u and b[2][6] != k:
			b[2][6] = k
			u.add(k)
			break
	for k in range(1, 10):
		if k not in u and b[3][1] != k:
			b[3][1] = k
			u.add(k)
			break
	for k in range(1, 10):
		if k not in u and b[4][4] != k:
			b[4][4] = k
			u.add(k)
			break
	for k in range(1, 10):
		if k not in u and b[5][7] != k:
			b[5][7] = k
			u.add(k)
			break
	for k in range(1, 10):
		if k not in u and b[6][2] != k:
			b[6][2] = k
			u.add(k)
			break
	for k in range(1, 10):
		if k not in u and b[7][5] != k:
			b[7][5] = k
			u.add(k)
			break
	f = 1
	for k in range(1, 10):
		if k not in u and b[8][8] != k:
			f = 0
			b[8][8] = k
			u.add(k)
			break
	if f == 1:
		b[8][8] = b[8][7]
	for e in b:
		print(''.join(map(str, e)))


from collections import Counter
t = int(input())
for _ in range(t):
	a = [[None for _ in range(9)] for _ in range(9)]
	for i in range(9):
		s = input()
		for j in range(9):
			a[i][j] = int(s[j])
	k = 0
	for i in range(0, 7, 3):
		j = 0
		c = 0
		while j < 9:
			if a[i + c][j + k] == 9:
				a[i + c][j + k] = 1
			else:
				a[i + c][j + k] = a[i + c][j + k] + 1
			j = j + 3
			c = c + 1
		k = k + 1
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


for t in range(int(input())):
	sudoku = []
	for i in range(9):
		row = list(input())
		sudoku.append(row)
	j = 0
	for i in range(0, 9, 3):
		if sudoku[0 + i][j] != '7':
			sudoku[0 + i][j] = '7'
		else:
			sudoku[0 + i][j] = '8'
		j += 1
	j = 3
	for i in range(0, 9, 3):
		if sudoku[1 + i][j] != '7':
			sudoku[1 + i][j] = '7'
		else:
			sudoku[1 + i][j] = '8'
		j += 1
	j = 6
	for i in range(0, 9, 3):
		if sudoku[2 + i][j] != '7':
			sudoku[2 + i][j] = '7'
		else:
			sudoku[2 + i][j] = '8'
		j += 1
	for row in sudoku:
		for cell in row:
			print(cell, end='')
		print()


t = int(input())
for i in range(t):
	for j in range(9):
		s = input()
		print(s.replace('2', '1'))


t = int(input())
for _ in range(t):
	G = [list(map(int, list(input()))) for i in range(9)]
	for j in range(0, 9):
		k = j // 3
		l = j % 3
		if l > 0:
			G[l * 3 + k][j] = G[0][j]
		else:
			G[k][j] = G[-1][j]
	for i in range(9):
		print(''.join(map(str, G[i])))


for _ in range(int(input())):
	for i in range(0, 9):
		s = input()
		list1 = list(s)
		for i in range(len(list1)):
			if list1[i] == '1':
				list1[i] = '2'
		str1 = ''.join(list1)
		print(str1)


t = int(input())
for _ in range(t):
	items = []
	for i in range(9):
		s = list(input())
		if i == 0:
			s[0] = str(int(s[0]) % 9 + 1)
		elif i == 1:
			s[3] = str(int(s[3]) % 9 + 1)
		elif i == 2:
			s[6] = str(int(s[6]) % 9 + 1)
		elif i == 3:
			s[1] = str(int(s[1]) % 9 + 1)
		elif i == 4:
			s[4] = str(int(s[4]) % 9 + 1)
		elif i == 5:
			s[7] = str(int(s[7]) % 9 + 1)
		elif i == 6:
			s[2] = str(int(s[2]) % 9 + 1)
		elif i == 7:
			s[5] = str(int(s[5]) % 9 + 1)
		elif i == 8:
			s[8] = str(int(s[8]) % 9 + 1)
		items.append(''.join(s))
	for item in items:
		print(item)


test = int(input())
lst = []
for _ in range(test):
	for k in range(9):
		tmplst = input()
		for i in range(len(tmplst) - 1):
			if tmplst[i] == '2':
				print('1', end='')
			else:
				print(tmplst[i], end='')
		if tmplst[-1] == '2':
			print('1')
		else:
			print(tmplst[-1])


t = int(input())
l = [[0 for i in range(9)] for j in range(9)]
for k in range(t):
	for i in range(9):
		x = input()
		for j in range(9):
			l[i][j] = int(x[j])
		r = i * 3 % 9 + int(i / 3)
		if l[i][r] == 9:
			l[i][r] = 1
		else:
			l[i][r] += 1
	for i in range(9):
		for j in range(9):
			print(l[i][j], end='')
		print('')


t = int(input())
for j in range(t):
	lista = []
	for i in range(9):
		lista.append(input())
	for i in range(9):
		if i == 0:
			if lista[i][0] != '1':
				print(lista[i][:0] + '1' + lista[i][0 + 1:])
			else:
				print(lista[i][:0] + '2' + lista[i][0 + 1:])
		if i == 1:
			if lista[i][3] != '1':
				print(lista[i][:3] + '1' + lista[i][3 + 1:])
			else:
				print(lista[i][:3] + '2' + lista[i][3 + 1:])
		if i == 2:
			if lista[i][6] != '1':
				print(lista[i][:6] + '1' + lista[i][6 + 1:])
			else:
				print(lista[i][:6] + '2' + lista[i][6 + 1:])
		if i == 3:
			if lista[i][1] != '1':
				print(lista[i][:1] + '1' + lista[i][1 + 1:])
			else:
				print(lista[i][:1] + '2' + lista[i][1 + 1:])
		if i == 4:
			if lista[i][4] != '1':
				print(lista[i][:4] + '1' + lista[i][4 + 1:])
			else:
				print(lista[i][:4] + '2' + lista[i][4 + 1:])
		if i == 5:
			if lista[i][7] != '1':
				print(lista[i][:7] + '1' + lista[i][7 + 1:])
			else:
				print(lista[i][:7] + '2' + lista[i][7 + 1:])
		if i == 6:
			if lista[i][2] != '1':
				print(lista[i][:2] + '1' + lista[i][2 + 1:])
			else:
				print(lista[i][:2] + '2' + lista[i][2 + 1:])
		if i == 7:
			if lista[i][5] != '1':
				print(lista[i][:5] + '1' + lista[i][5 + 1:])
			else:
				print(lista[i][:5] + '2' + lista[i][5 + 1:])
		if i == 8:
			if lista[i][8] != '1':
				print(lista[i][:8] + '1' + lista[i][8 + 1:])
			else:
				print(lista[i][:8] + '2' + lista[i][8 + 1:])


t = int(input())
sudoku = []
sudokurow = []
for k in range(t):
	sudoku = []
	for i in range(9):
		sudokuvalue = int(input())
		sudokurow = [int(d) for d in str(sudokuvalue)]
		sudoku += [sudokurow]
	sudokurow = []
	for i in range(9):
		for j in range(9):
			if sudoku[i][j] == 1:
				sudoku[i][j] = 2
	for i in range(9):
		for j in range(9):
			print(sudoku[i][j], end='')
		print(end='\n')


def rep(data):
	for j in range(len(data)):
		if data[j] == '1':
			data[j] = '2'
			break
	print(''.join(data))
t = int(input())
for i in range(t * 9):
	data = list(input())
	rep(data)


for _ in range(int(input())):
	l = []
	for i in range(3):
		s = input()
		l.append(s)
	for i in range(3):
		for j in range(9):
			if i == 0 and j == 0:
				if l[i][j] != '1':
					print(1, end='')
				else:
					print(2, end='')
				continue
			if i == 1 and j == 3:
				if l[i][j] != '1':
					print(1, end='')
				else:
					print(2, end='')
				continue
			if i == 2 and j == 6:
				if l[i][j] != '1':
					print(1, end='')
				else:
					print(2, end='')
				continue
			print(l[i][j], end='')
		print()
	l = []
	for i in range(3):
		s = input()
		l.append(s)
	for i in range(3):
		for j in range(9):
			if i == 0 and j == 1:
				if l[i][j] != '1':
					print(1, end='')
				else:
					print(2, end='')
				continue
			if i == 1 and j == 4:
				if l[i][j] != '1':
					print(1, end='')
				else:
					print(2, end='')
				continue
			if i == 2 and j == 7:
				if l[i][j] != '1':
					print(1, end='')
				else:
					print(2, end='')
				continue
			print(l[i][j], end='')
		print()
	l = []
	for i in range(3):
		s = input()
		l.append(s)
	for i in range(3):
		for j in range(9):
			if i == 0 and j == 2:
				if l[i][j] != '1':
					print(1, end='')
				else:
					print(2, end='')
				continue
			if i == 1 and j == 5:
				if l[i][j] != '1':
					print(1, end='')
				else:
					print(2, end='')
				continue
			if i == 2 and j == 8:
				if l[i][j] != '1':
					print(1, end='')
				else:
					print(2, end='')
				continue
			print(l[i][j], end='')
		print()
	print()


import math
from collections import Counter
for _ in range(int(input())):
	a = []
	for i in range(9):
		a.append(list(input()))
	l = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for (i, j) in l:
		a[i][j] = str(int(a[i][j]) + 1) if a[i][j] != '9' else '1'
	for i in a:
		print(''.join(i))


t = int(input())
for _ in range(t):
	a = [input() for _ in range(9)]
	for row in a:
		print(row.replace('1', '2', 1))


def main():
	t = int(input())
	for i in range(t):
		for j in range(9):
			print(input().replace('1', '6', 1))
main()


import sys
input = sys.stdin.readline

def inputnum():
	return int(input())

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

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

def inputstring():
	s = input()
	return list(s[:len(s) - 1])
t = int(input())
for q in range(t):
	suduku = []
	for i in range(9):
		s1 = inputstring()
		suduku.append(s1)
	for i in range(9):
		for j in range(9):
			if suduku[i][j] == '1':
				suduku[i][j] = '2'
			print(suduku[i][j], end='')
		print()


import sys
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize
sys.setrecursionlimit(10 ** 7)
mod = 1000000007

def IOE():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		for i in range(1, 10):
			s = input()
			s = s.replace('2', '1')
			print(s)
try:
	IOE()
except:
	pass
main()


t = int(input())
data = '234567891'
for i in range(t):
	for j in range(9):
		k = j % 3 * 3 + j // 3
		a = list(input())
		a[k] = data[int(a[k]) - 1]
		print(''.join(a))


t = int(input())
for i in range(t):
	for j in range(9):
		s = input()
		print(s.replace('3', '4'))


test_cases = int(input())
tests = []
for t in range(test_cases):
	sudoku = []
	for lin in range(9):
		line = [int(char) for char in input()]
		sudoku.append(line)
	tests.append(sudoku)
for test in tests:
	ts = test
	xpos = 0
	ypos = 0
	for line in ts:
		for integer in line:
			if integer == 2:
				line[ypos] = 1
			ypos += 1
		xpos += 1
		ypos = 0
	for lin in ts:
		line = ''
		for char in lin:
			line += str(char)
		print(line)
	xpos = 0


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	block = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for _ in [0] * T:
		S = [list(input()) for _ in [0] * 9]
		for (r, c) in block:
			n = int(S[r][c]) + 1
			if n == 10:
				n = 1
			S[r][c] = str(n)
		ans = [''.join(s) for s in S]
		print(*ans, sep='\n')
main()


t = int(input())
for i in range(t):
	x1 = input()
	x2 = input()
	x3 = input()
	x4 = input()
	x5 = input()
	x6 = input()
	x7 = input()
	x8 = input()
	x9 = input()
	print(x1.replace(x1[6], x1[5]))
	print(x2.replace(x2[1], x2[0]))
	print(x3.replace(x3[5], x3[8]))
	print(x4.replace(x4[8], x4[5]))
	print(x5.replace(x5[2], x5[0]))
	print(x6.replace(x6[4], x6[7]))
	print(x7.replace(x7[7], x7[6]))
	print(x8.replace(x8[0], x8[1]))
	print(x9.replace(x9[3], x9[2]))


t = int(input())
while t > 0:
	mx = []
	for i in range(9):
		mx.append(list(input()))
	mx[0][0] = mx[0][1]
	mx[1][3] = mx[1][4]
	mx[2][6] = mx[2][7]
	mx[3][1] = mx[3][2]
	mx[4][4] = mx[4][5]
	mx[5][7] = mx[5][8]
	mx[6][2] = mx[6][1]
	mx[7][5] = mx[7][4]
	mx[8][8] = mx[8][7]
	for j in range(9):
		print(''.join(mx[j]))
	t -= 1


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	grid = [''] * 9
	for i in range(9):
		grid[i] = input()
	for i in range(9):
		grid[i] = grid[i].replace('1', '2')
		print(''.join(grid[i]))


import string
for t in range(int(input())):
	r = []
	for i in range(1, 10):
		b = list(input())
		for j in range(9):
			if b[j] == '9':
				b[j] = '1'
		print(''.join(b))


from math import *
t = int(input())
for _ in range(t):
	l = []
	for i in range(9):
		s = input()
		k = list(s)
		l.append(k)
	for i in range(9):
		for j in range(9):
			if l[i][j] == '3':
				l[i][j] = '5'
	for i in range(9):
		for j in range(9):
			print(l[i][j], end='')
		print()


t = int(input())
for i in range(t):
	lst = []
	for j in range(9):
		a = input()
		for k in a:
			k = int(k)
			if k == 9:
				k = 1
				lst.append(k)
			else:
				lst.append(k)
	b = [0, 9, 18, 27, 36, 45, 54, 63, 72]
	for m in b:
		print('\n')
		for l in range(9):
			print(lst[l + m], end='')


for _ in range(int(input())):
	sudoku = [[] for i in range(9)]
	for i in range(9):
		sudoku[i] = [int(x) for x in input()]
	sudoku[0][0] = sudoku[0][0] + 1 if sudoku[0][0] != 9 else 1
	sudoku[1][3] = sudoku[1][3] + 1 if sudoku[1][3] != 9 else 1
	sudoku[2][6] = sudoku[2][6] + 1 if sudoku[2][6] != 9 else 1
	sudoku[3][1] = sudoku[3][1] + 1 if sudoku[3][1] != 9 else 1
	sudoku[4][4] = sudoku[4][4] + 1 if sudoku[4][4] != 9 else 1
	sudoku[5][7] = sudoku[5][7] + 1 if sudoku[5][7] != 9 else 1
	sudoku[6][2] = sudoku[6][2] + 1 if sudoku[6][2] != 9 else 1
	sudoku[7][5] = sudoku[7][5] + 1 if sudoku[7][5] != 9 else 1
	sudoku[8][8] = sudoku[8][8] + 1 if sudoku[8][8] != 9 else 1
	for i in range(9):
		print(''.join((str(x) for x in sudoku[i])))


t = int(input())
for u in range(t):
	for i in range(9):
		s = list(input())
		for j in range(len(s)):
			if s[j] == '1':
				s[j] = '2'
		s = ''.join(s)
		print(s)


t = int(input())

def solve(g):
	g[0][0] = 1 if g[0][0] != 1 else 2
	g[1][4] = 1 if g[1][4] != 1 else 2
	g[2][8] = 1 if g[2][8] != 1 else 2
	g[3][7] = 1 if g[3][7] != 1 else 2
	g[4][1] = 1 if g[4][1] != 1 else 2
	g[5][3] = 1 if g[5][3] != 1 else 2
	g[6][6] = 1 if g[6][6] != 1 else 2
	g[7][2] = 1 if g[7][2] != 1 else 2
	g[8][5] = 1 if g[8][5] != 1 else 2
	return grid

def checkAnti(g):
	for r in grid:
		fine = False
		seen = set()
		for d in r:
			if d in seen:
				fine = True
				break
			else:
				seen.add(d)
	if not fine:
		print('BAD')
	for c in range(0, len(grid[0])):
		fine = False
		seen = set()
		for r in grid:
			if r[c] in seen:
				fine = True
				break
			else:
				seen.add(r[c])
	if not fine:
		print('BAD')
	for n in range(0, 9):
		for j in [[0, 1, 2], [3, 4, 5], [6, 7, 8]]:
			for i in [[0, 1, 2], [3, 4, 5], [6, 7, 8]]:
				fine = False
				seen = set()
				for jx in j:
					for ix in i:
						if grid[jx][ix] in seen:
							fine = True
							break
						else:
							seen.add(grid[jx][ix])
	if not fine:
		print('BAD')
for _ in range(0, t):
	grid = []
	for _ in range(0, 9):
		grid.append(list(map(int, list(str(input())))))
	a = solve(grid)
	for l in grid:
		print(''.join(list(map(str, l))))


import sys
import math
from itertools import permutations
input = lambda : sys.stdin.readline().strip()
t = int(input())

def set_val(a, b):
	temp = su[a][b]
	for k in range(9):
		if k + 1 != su[a][b] and (not vis[k]):
			vis[k] = True
			su[a][b] = k + 1
			break
	if su[a][b] == temp:
		print(vis)
		print('Yes', a, b, temp)
while t:
	t -= 1
	su = []
	for i in range(9):
		su.append(list(map(int, list(input()))))
	vis = [False] * 9
	val = [[1, 1, su[1][1]], [4, 4, su[4][4]], [7, 7, su[7][7]], [0, 3, su[0][3]], [2, 6, su[2][6]], [3, 0, su[3][0]], [5, 8, su[5][8]], [6, 2, su[6][2]], [8, 5, su[8][5]]]
	for i in val:
		if i[2] == 5:
			su[i[0]][i[1]] = 6
		else:
			su[i[0]][i[1]] = 10 - i[2]
	for i in range(9):
		print(''.join(map(str, su[i])))


for i in range(int(input())):
	(k, l, m) = (-1, 2, 5)
	for j in range(9):
		x = input()
		rem = j % 3
		if rem == 0:
			print(x.replace(x[k + 1], x[k + 2]))
		elif rem == 1:
			print(x.replace(x[l + 1], x[l + 2]))
		else:
			print(x.replace(x[m + 1], x[m - 2]))
			k += 1
			l += 1
			m += 1


def sub(i, x, y):
	grid[i][x][y] -= 1
	if grid[i][x][y] == 0:
		grid[i][x][y] = 9
t = int(input())
grid = []
for i in range(t):
	grid.append([])
	for j in range(9):
		grid[i].append([int(d) for d in input()])
for i in range(t):
	sub(i, 0, 0)
	sub(i, 3, 1)
	sub(i, 6, 2)
	sub(i, 1, 3)
	sub(i, 4, 4)
	sub(i, 7, 5)
	sub(i, 2, 6)
	sub(i, 5, 7)
	sub(i, 8, 8)
	for j in range(9):
		print(''.join([str(grid[i][j]) for grid[i][j] in grid[i][j]]))


t = int(input())
for _ in range(t):
	mat = []
	for _ in range(9):
		row = list(map(int, input()))
		mat.append(row)
	for i in range(9):
		(x, y) = divmod(i, 3)
		j = x + 3 * y
		a = 10 - mat[i][j]
		mat[i][j] = 1 if a == 5 else a
		row = ''.join(map(str, mat[i]))
		print(row)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def in_int():
	return int(input())

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

def in_str():
	s = input()
	return list(s[:len(s) - 1])

def in_ints():
	return map(int, input().split())
t = in_int()
for tt in range(t):
	a = [in_str() for i in range(9)]
	for i in range(9):
		for j in range(9):
			a[i][j] = int(a[i][j])
	for i in range(3):
		for j in range(3):
			k = a[3 * i + j][3 * j + i]
			if k < 9:
				a[3 * i + j][3 * j + i] = 9
			else:
				a[3 * i + j][3 * j + i] = 1
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


n = int(input())
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
q = [1, 4, 7, 2, 5, 8, 3, 6, 9]
for i in range(0, n):
	w = []
	A = 0
	for j in range(0, 9):
		o = input().rstrip()
		x = list(o)
		w.append(x)
	for j in range(0, len(w)):
		X = int(w[j][q[A] - 1])
		for k in range(0, len(l)):
			if l[k] != X:
				w[j][q[A] - 1] = str(l[k])
				break
		A += 1
		print(''.join(w[j]))


def main():
	for _ in inputt():
		for _ in range(9):
			s = input()
			print(s.replace('1', '2'))
from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict, deque
import re, copy, operator, cmath
import calendar
import sys, io, os, builtins
sys.setrecursionlimit(1000)
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	sys.stdout.write(kwargs.pop('split', ' ').join(map(str, args)))
	sys.stdout.write(kwargs.pop('end', '\n'))
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip()
inputt = lambda t=0: range(t) if t else range(int(input()))
inputs = lambda : input().split()
inputi = lambda k=int: map(k, inputs())
inputf = lambda : inputi(float)
inputl = lambda t=0, k=inputi: map(list, (k() for _ in range(t))) if t else list(k())

def len(a):
	if isinstance(a, range):
		return -((a.start - a.stop) // a.step)
	return builtins.len(a)

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

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

def insort_left(a, x, key=None, lo=0, hi=None):
	lo = bisect_left(a, x, key, lo, hi)
	a.insert(lo, x)

def insort_right(a, x, key=None, lo=0, hi=None):
	lo = bisect_right(a, x, key, lo, hi)
	a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right

def index(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	if key == None:
		key = do_nothing
	i = bisect_left(a, x, key, lo, hi)
	if lo <= i < hi and key(a[i]) == x:
		return a[i]
	if default != None:
		return default
	raise ValueError

def find_lt(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	i = bisect_left(a, x, key, lo, hi)
	if lo < i <= hi:
		return a[i - 1]
	if default != None:
		return default
	raise ValueError

def find_le(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	i = bisect_right(a, x, key, lo, hi)
	if lo < i <= hi:
		return a[i - 1]
	if default != None:
		return default
	raise ValueError

def find_gt(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	i = bisect_right(a, x, key, lo, hi)
	if lo <= i < hi:
		return a[i]
	if default != None:
		return default
	raise ValueError

def find_ge(a, x, default=None, key=None, lo=0, hi=None):
	if lo < 0:
		lo = 0
	if hi == None:
		hi = len(a)
	i = bisect_left(a, x, key, lo, hi)
	if lo <= i < hi:
		return a[i]
	if default != None:
		return default
	raise ValueError
main()


case = int(input())
for i in range(case):
	for j in range(9):
		x = input().strip('\n\r')
		print(x.replace('1', '2'))


for _ in range(int(input())):
	A = []
	n = 9
	for i in range(n):
		A.append(list(input()))
	m = len(A[0])
	change = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for c in change:
		i = c[0]
		j = c[1]
		if A[i][j] == '8':
			A[i][j] = '9'
		else:
			A[i][j] = '8'
	for i in range(n):
		A[i] = ''.join(A[i])
	for i in range(9):
		print(A[i])


from math import *
from collections import *
from operator import itemgetter
import bisect
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
t = ii()
idx = [[0, 8], [1, 5], [2, 2], [3, 1], [4, 4], [5, 7], [6, 0], [7, 3], [8, 6]]
ans = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 1], [7, 0], [8, 0]]
for _ in range(t):
	s = []
	a = []
	for i in range(9):
		s.append(list(input()))
	k = 0
	for i in range(9):
		s[idx[i][0]][idx[i][1]] = s[ans[i][0]][ans[i][1]]
		print(*s[i], sep='')


for _ in range(int(input())):
	a = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for i in range(9):
		s = str(input())
		l = list(s)
		r = ''
		for j in range(9):
			if j == a[i][1]:
				if l[j] != '9':
					r += '9'
				else:
					r += '6'
			else:
				r += l[j]
		print(r)


for _ in range(int(input())):
	l = []
	for i in range(9):
		a = input()
		l1 = []
		for j in a:
			l1.append(int(j))
		l.append(l1)
	j = 0
	l[0][0] = l[1][0]
	l[1][3] = l[2][3]
	l[2][6] = l[0][6]
	l[3][1] = l[4][1]
	l[4][4] = l[5][4]
	l[5][7] = l[3][7]
	l[6][2] = l[7][2]
	l[7][5] = l[8][5]
	l[8][8] = l[6][8]
	for i in range(9):
		g = ''
		for j in range(9):
			g += str(l[i][j])
		print(g)


t = int(input())
for tt in range(t):
	m = []
	for i in range(9):
		m.append(list(input()))
	m[0][0] = m[1][0]
	m[3][1] = m[4][1]
	m[6][2] = m[7][2]
	m[1][0 + 3] = m[2][0 + 3]
	m[4][1 + 3] = m[5][1 + 3]
	m[7][2 + 3] = m[8][2 + 3]
	m[2][0 + 6] = m[0][0 + 6]
	m[5][1 + 6] = m[3][1 + 6]
	m[8][2 + 6] = m[6][2 + 6]
	for i in range(9):
		print(''.join(m[i]))


import sys
sys.setrecursionlimit(10 ** 7)
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
t = ni()
for i in range(t):
	m = [list(ns()) for i in range(9)]
	for j in range(9):
		for k in range(9):
			if m[j][k] == '1':
				print('2', end='')
			else:
				print(m[j][k], end='')
		print()


for _ in range(int(input())):
	matrix = []
	for i in range(9):
		s = input()
		row = []
		for j in range(len(s)):
			row.append(ord(s[j]) - ord('0'))
		matrix.append(row)
	for i in range(0, 9):
		for j in range(0, 9):
			if matrix[i][j] == 1:
				matrix[i][j] = 2
	for i in range(9):
		for j in range(9):
			print(matrix[i][j], end='')
		print()


import sys
import string
input = sys.stdin.readline
tc = int(input())
for _ in range(tc):
	l = list()
	for _ in range(9):
		t = input()
		l.append(t)
	for x in l:
		for i in range(9):
			if x[i] == '1':
				print(2, end='')
			else:
				print(x[i], end='')
		print()


List = [(1, 1), (2, 4), (3, 7), (4, 2), (5, 5), (6, 8), (7, 3), (8, 6), (9, 9)]
for _ in range(int(input())):
	Matrix = []
	for i in range(9):
		T = input()
		X = []
		for x in T:
			X.append(int(x))
		Matrix.append(X)
	for i in List:
		Q = Matrix[i[0] - 1][i[1] - 1] + 1
		if Q == 9:
			Matrix[i[0] - 1][i[1] - 1] = 9
		else:
			Matrix[i[0] - 1][i[1] - 1] = Q % 9
	for i in range(9):
		S = ''
		for j in range(9):
			S += str(Matrix[i][j])
		print(S)


def sol(arr):
	for i in range(9):
		for r in range(9):
			if arr[i][r] == '2':
				if 0 < r < 8:
					arr[i] = arr[i][:r] + '1' + arr[i][r + 1:]
					break
				elif r == 8:
					arr[i] = arr[i][:r] + '1'
					break
				elif r == 0:
					arr[i] = '1' + arr[i][r + 1:]
					break
	for i in range(9):
		print(arr[i])
	return
for t in range(int(input())):
	arr = []
	for i in range(9):
		arr.append(input())
	sol(arr)


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	lis = []
	for i in range(9):
		s = ri()
		temp = [i for i in s]
		lis.append(temp)
	y = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	x = [0, 1, 2, 3, 4, 5, 6, 7, 8]
	for i in range(9):
		val = int(lis[x[i]][y[i]])
		val = (val + 1) % 9
		if val == 0:
			val = 9
		lis[x[i]][y[i]] = val
	for i in lis:
		print(''.join(map(str, i)))


t = int(input())
for _ in range(0, t):
	lst = []
	for _ in range(0, 9):
		s = [i for i in input()]
		lst.append(s)
	for i in range(0, 9):
		for j in range(0, 9):
			if lst[i][j] == '5':
				lst[i][j] = '6'
	for i in lst:
		print(''.join(i))


t = int(input())
while t:
	mat = []
	for i in range(9):
		temp = list(input())
		mat.append([int(i) for i in temp])
	i = 0
	for k in range(3):
		if mat[i][k] != 9:
			mat[i][k] += 1
		else:
			mat[i][k] = 1
		if mat[i + 1][k + 3] != 9:
			mat[i + 1][k + 3] += 1
		else:
			mat[i + 1][k + 3] = 1
		if mat[i + 2][k + 6] != 9:
			mat[i + 2][k + 6] += 1
		else:
			mat[i + 2][k + 6] = 1
		i += 3
	for i in range(9):
		print(*mat[i], sep='')
	t -= 1


import sys
from functools import lru_cache
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def outln(var):
	sys.stdout.write(str(var) + '\n')

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	mat = []
	for i in range(9):
		mat.append(list(data()))
	if mat[0][0] != '5':
		mat[0][0] = str(10 - int(mat[0][0]))
	else:
		mat[0][0] = '1'
	if mat[5][5] != '5':
		mat[5][5] = str(10 - int(mat[5][5]))
	else:
		mat[5][5] = '1'
	if mat[7][7] != '5':
		mat[7][7] = str(10 - int(mat[7][7]))
	else:
		mat[7][7] = '1'
	if mat[8][2] != '5':
		mat[8][2] = str(10 - int(mat[8][2]))
	else:
		mat[8][2] = '1'
	if mat[3][6] != '5':
		mat[3][6] = str(10 - int(mat[3][6]))
	else:
		mat[3][6] = '1'
	if mat[4][1] != '5':
		mat[4][1] = str(10 - int(mat[4][1]))
	else:
		mat[4][1] = '1'
	if mat[6][3] != '5':
		mat[6][3] = str(10 - int(mat[6][3]))
	else:
		mat[6][3] = '1'
	if mat[2][8] != '5':
		mat[2][8] = str(10 - int(mat[2][8]))
	else:
		mat[2][8] = '1'
	if mat[1][4] != '5':
		mat[1][4] = str(10 - int(mat[1][4]))
	else:
		mat[1][4] = '1'
	for i in mat:
		outln(''.join(i))


t = int(input())
while t:
	ite = 9
	res = []
	idx = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	k = 0
	while ite:
		st = input()
		int_list = [int(st[i:i + 1]) for i in range(0, len(st), 1)]
		if int_list[idx[k]] < 9:
			int_list[idx[k]] += 1
		else:
			int_list[idx[k]] = 1
		res.append(''.join(map(str, int_list)))
		ite -= 1
		k += 1
	for i in range(9):
		print(res[i])
	t -= 1


import collections, math, bisect
local = False
if local:
	file = open('input.txt', 'r')
	import time

def inp():
	if local:
		return file.readline().rstrip()
	else:
		return input().rstrip()

def ints():
	return [int(_) for _ in inp().split()]
if local:
	start = time.time()
t = int(inp())
for _ in range(1, t + 1):
	grid = [[0 for c in range(9)] for r in range(9)]
	for r in range(9):
		row = inp()
		for c in range(9):
			grid[r][c] = row[c]
	grid[0][0] = grid[0][1]
	grid[1][3] = grid[1][4]
	grid[2][6] = grid[2][7]
	grid[3][1] = grid[3][2]
	grid[4][4] = grid[4][5]
	grid[5][7] = grid[5][8]
	grid[6][2] = grid[6][1]
	grid[7][5] = grid[7][4]
	grid[8][8] = grid[8][7]
	for r in range(9):
		print(''.join(grid[r]))
if local:
	fin = (time.time() - start) * 1000
	print('{:.2f}'.format(fin) + 'ms')


for _ in range(int(input())):
	l = []
	for i in range(9):
		temp = []
		for i in input():
			temp.append(int(i))
		l.append(temp)
	ind = 0
	for i in range(3):
		for j in range(0, 9, 3):
			if i + j < 8:
				l[ind][i + j] = l[ind][i + j + 1]
				ind += 1
			else:
				l[ind][i + j] = l[ind][i + j - 1]
				ind += 1
	for i in range(9):
		for j in range(9):
			print(l[i][j], end='')
		print()


import sys
input = sys.stdin.buffer.readline
import collections

def inc(u):
	return str(int(u) % 9 + 1)

def solve(arr):
	arr[0][0] = inc(arr[0][0])
	arr[1][3] = inc(arr[1][3])
	arr[2][6] = inc(arr[2][6])
	arr[3][1] = inc(arr[3][1])
	arr[4][4] = inc(arr[4][4])
	arr[5][7] = inc(arr[5][7])
	arr[6][2] = inc(arr[6][2])
	arr[7][5] = inc(arr[7][5])
	arr[8][8] = inc(arr[8][8])
	for i in range(9):
		print(''.join(arr[i]))
t = int(input())
for _ in range(t):
	arr = []
	for i in range(9):
		st = list(str(int(input())))
		arr.append(st)
	solve(arr)


def solve():
	x = []
	for i in range(9):
		x.append(list(input()))
	x[0][0] = x[0][1]
	x[1][3] = x[1][4]
	x[2][6] = x[2][7]
	x[3][1] = x[3][2]
	x[4][4] = x[4][5]
	x[5][7] = x[5][8]
	x[6][2] = x[6][3]
	x[7][5] = x[7][6]
	x[8][8] = x[8][7]
	for i in range(9):
		ans = ''.join(x[i])
		print(ans)
t = int(input())
for i in range(t):
	solve()


def solution(grid):
	for i in range(len(grid)):
		for j in range(len(grid[0])):
			if grid[i][j] == 1:
				grid[i][j] = 2
	for row in grid:
		string = ''
		print(string.join([str(ele) for ele in row]))
test_case = int(input())
test_input = []
for i in range(test_case):
	grid = []
	for j in range(9):
		ar = [int(x) for x in str(input())]
		grid.append(ar)
	test_input.append(grid)
for test in test_input:
	solution(test)


t = int(input())
for i in range(t):
	s = []
	for i in range(9):
		n = input()
		s.append(n)
	for i in range(9):
		for j in range(9):
			if s[i][j] == '1':
				s[i] = s[i][0:j] + '2' + s[i][j + 1:]
		print(s[i])


from sys import stdin, stdout

def f(a):
	a[0][1] = a[0][0]
	a[1][4] = a[1][3]
	a[2][7] = a[2][6]
	a[3][2] = a[3][1]
	a[4][5] = a[4][4]
	a[5][8] = a[5][7]
	a[6][0] = a[6][1]
	a[7][3] = a[7][2]
	a[8][6] = a[8][5]
	ans = ''
	for i in range(9):
		for j in range(9):
			ans += str(a[i][j])
		if i != 8:
			ans += '\n'
	print(ans)
t = int(stdin.readline())
for _ in range(t):
	a = []
	for i in range(9):
		b = input()
		c = []
		for i in b:
			c.append(int(i))
		a.append(c)
	f(a)


for _ in range(int(input())):
	s = []
	for i in range(9):
		s.append(list(input()))
	for i in range(9):
		for j in range(9):
			if s[i][j] == '1':
				s[i][j] = '2'
	for i in range(9):
		print(''.join(s[i]))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	board = []
	for _ in range(9):
		line = list(map(int, input()))
		board.append(line)
	board[0][0] = board[1][0]
	board[1][4] = board[1][5]
	board[2][8] = board[2][7]
	board[3][1] = board[3][2]
	board[4][5] = board[4][4]
	board[5][6] = board[5][7]
	board[6][2] = board[6][1]
	board[7][3] = board[7][4]
	board[8][7] = board[8][8]
	for y in board:
		for x in y:
			print(x, end='')
		print()


for t in range(int(input())):
	a = [[int(d) for d in input()] for i in range(9)]

	def f(x):
		return 1 if x != 1 else 2
	for i in range(9):
		a[3 * (i % 3) + i // 3][i] = f(a[3 * (i % 3) + i // 3][i])
	for i in range(9):
		print(''.join([str(x) for x in a[i]]))


import sys
import math
T = int(sys.stdin.readline())
for _ in range(T):
	g = []
	for i in range(9):
		g.append(list(sys.stdin.readline())[:-1])
	for i in range(3):
		for j in range(3):
			if g[i * 3 + j][j * 3 + i] == '7':
				g[i * 3 + j][j * 3 + i] = '9'
			else:
				g[i * 3 + j][j * 3 + i] = '7'
	for i in range(9):
		print(''.join(g[i]))


t = int(input())
for ts in range(t):
	ii = [0, 4, 7, 8, 1, 5, 3, 6, 2]
	for i in range(9):
		a = list(input())
		a[ii[i]] = str(int(a[ii[i]]) + 1)
		if a[ii[i]] == '10':
			a[ii[i]] = '1'
		print(''.join(a))


for _ in range(int(input())):
	s = []
	for i in range(9):
		s.append(list(input()))
	k = 0
	p = 0
	for i in range(0, 9, 3):
		p = 0
		for j in range(k, 9, 3):
			if j < 8:
				s[i + p][j] = s[i + p][j + 1]
			else:
				s[i + p][j] = s[i + p][j - 1]
			p += 1
		k += 1
	for i in s:
		print(''.join(i))


t = int(input())
for _ in range(t):
	grid = [input() for _ in range(9)]
	grid = [r.replace('1', '2') for r in grid]
	print('\n'.join(grid))


for _ in range(int(input())):
	for i in range(9):
		k = input()
		k = list(k)
		for j in range(len(k)):
			if k[j] == '1':
				k[j] = '2'
		listToStr = ''.join([str(elem) for elem in k])
		print(listToStr)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	ntest = int(stdin.readline())
	for test in range(ntest):
		sud = [list(stdin.readline().strip()) for i in range(9)]
		for i in range(9):
			for j in range(9):
				if sud[i][j] == '2':
					sud[i][j] = '1'
			stdout.write('%s\n' % ''.join(sud[i]))
	return 0
main()


import sys
import random
from math import log2, log, ceil
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def primefs(n):
	if n == 1:
		return 1
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]
spf_sieve()

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().split()))
for _ in range(int(input())):
	grid = [[None for _ in range(9)] for _ in range(9)]
	for i in range(9):
		string = input().strip()
		for j in range(9):
			grid[i][j] = int(string[j])
	inds = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
	for i in inds:
		(x, y) = i
		if grid[x][y] == 1:
			grid[x][y] += 1
		else:
			grid[x][y] -= 1
	for i in range(9):
		for j in range(9):
			if j != 8:
				print(grid[i][j], end='')
			else:
				print(grid[i][j])


for _ in range(int(input())):
	arr = []
	for i in range(9):
		t = [int(ord(x) - ord('0')) for x in input()]
		arr.append(t)
	for i in range(9):
		for j in range(9):
			if arr[i][j] == 2:
				arr[i][j] = 3
	for i in range(9):
		for j in range(9):
			print(arr[i][j], end='')
		print('')


from collections import defaultdict
t = int(input())
for _ in range(t):
	sudoku = []
	for _ in range(9):
		temp = input()
		sudoku.append(list(map(int, temp)))
	sudoku[0][0] = sudoku[0][1]
	sudoku[1][3] = sudoku[1][4]
	sudoku[2][6] = sudoku[2][7]
	sudoku[3][1] = sudoku[3][2]
	sudoku[4][4] = sudoku[4][5]
	sudoku[5][7] = sudoku[5][8]
	sudoku[6][2] = sudoku[6][1]
	sudoku[7][5] = sudoku[7][4]
	sudoku[8][8] = sudoku[8][7]
	for i in sudoku:
		print(*i, sep='')


for _ in range(int(input())):
	arr = []
	for i in range(0, 9):
		arr.append(input())
	if arr[0][0] == '1':
		arr[0] = arr[0][0:0] + str(2) + arr[0][1:]
	else:
		arr[0] = arr[0][0:0] + str(1) + arr[0][1:]
	if arr[1][3] == '1':
		arr[1] = arr[1][0:3] + str(2) + arr[1][4:]
	else:
		arr[1] = arr[1][0:3] + str(1) + arr[1][4:]
	if arr[2][6] == '1':
		arr[2] = arr[2][:6] + str(2) + arr[2][7:]
	else:
		arr[2] = arr[2][:6] + str(1) + arr[2][7:]
	if arr[3][1] == '1':
		arr[3] = arr[3][:1] + str(2) + arr[3][2:]
	else:
		arr[3] = arr[3][:1] + str(1) + arr[3][2:]
	if arr[4][4] == '1':
		arr[4] = arr[4][:4] + str(2) + arr[4][5:]
	else:
		arr[4] = arr[4][:4] + str(1) + arr[4][5:]
	if arr[5][7] == '1':
		arr[5] = arr[5][:7] + str(2) + arr[5][8:]
	else:
		arr[5] = arr[5][:7] + str(1) + arr[5][8:]
	if arr[6][2] == '1':
		arr[6] = arr[6][:2] + str(2) + arr[6][3:]
	else:
		arr[6] = arr[6][:2] + str(1) + arr[6][3:]
	if arr[7][5] == '1':
		arr[7] = arr[7][:5] + str(2) + arr[7][6:]
	else:
		arr[7] = arr[7][:5] + str(1) + arr[7][6:]
	if arr[8][8] == '1':
		arr[8] = arr[8][:8] + str(2) + arr[8][9:]
	else:
		arr[8] = arr[8][:8] + str(1) + arr[8][9:]
	for i in range(0, 9):
		print(arr[i])


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

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

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
t = int(input())
while t:
	t -= 1
	a = [[int(x) for x in input()] for i in range(9)]
	a[2][0] = a[0][0]
	a[1][3] = a[0][3]
	a[0][7] = a[0][6]
	a[5][1] = a[3][1]
	a[4][4] = a[3][4]
	a[3][8] = a[3][7]
	a[8][2] = a[6][2]
	a[7][5] = a[6][5]
	a[6][6] = a[7][6]
	for i in range(9):
		print(*a[i], sep='')


t = int(input())
for _ in range(t):
	tab = []
	for i in range(9):
		tab.append(list(input().strip()))
	tab[0][0] = tab[0][1]
	tab[3][1] = tab[3][2]
	tab[6][2] = tab[6][1]
	tab[1][3] = tab[1][4]
	tab[4][4] = tab[4][5]
	tab[7][5] = tab[7][4]
	tab[2][6] = tab[2][7]
	tab[5][7] = tab[5][8]
	tab[8][8] = tab[8][7]
	for it in tab:
		print(''.join(it))


t = int(input())
for _ in range(t):
	l = []
	for i in range(9):
		l.append(list(input()))
	l[0][-3] = l[0][-4]
	l[1][1] = l[1][0]
	l[2][-4] = l[2][-1]
	l[3][-1] = l[3][-4]
	l[4][2] = l[4][0]
	l[5][-5] = l[5][-2]
	l[6][-2] = l[6][-3]
	l[7][0] = l[7][1]
	l[8][3] = l[8][2]
	for i in range(9):
		print(''.join(l[i]))


from sys import stdin
for i in range(int(stdin.readline())):
	a = []
	for j in range(9):
		a.append([int(x) for x in str(int(stdin.readline()))])
	a[0][0] = a[1][0]
	a[1][3] = a[0][3]
	a[2][6] = a[1][6]
	a[3][1] = a[4][1]
	a[4][4] = a[3][4]
	a[5][7] = a[4][7]
	a[6][2] = a[7][2]
	a[7][5] = a[6][5]
	a[8][8] = a[7][8]
	print('')
	for j in range(9):
		for k in range(9):
			print(a[j][k], end='')
		print('')


from collections import Counter
for _ in range(int(input())):
	for _ in range(9):
		s = input()
		for i in s:
			if i == '1':
				print('2', end='')
			else:
				print(i, end='')
		print()


for q in range(int(input())):
	li = []
	for t in range(9):
		li.append(input())
	d = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for f in range(9):
		(i, j) = (d[f][0], d[f][1])
		if li[i][j] != '1':
			li[i] = li[i][:j] + '1' + li[i][j + 1:]
		else:
			li[i] = li[i][:j] + '2' + li[i][j + 1:]
		print(li[f])


from math import ceil, gcd, floor, log
from collections import deque, defaultdict
from heapq import heappush as hpush, heappop as hpop, heapify
from functools import lru_cache
import sys

def inpi():
	return int(input())

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

def inp():
	s = input()
	return list(s)

def inpv():
	return map(int, input().split())
l = 'abcdefghijklmnopqrstuvwxyz'
testcase = int(input())
for test in range(testcase):
	a = []
	for i in range(9):
		a.append(inp())
	for i in range(0, 9, 3):
		if i == 0:
			a[1][i] = a[0][i]
		elif i == 3:
			a[2][i] = a[1][i]
		else:
			a[0][i] = a[2][i]
	for i in range(1, 9, 3):
		if i == 1:
			a[1 + 3][i] = a[0 + 3][i]
		elif i == 3 + 1:
			a[2 + 3][i] = a[1 + 3][i]
		else:
			a[0 + 3][i] = a[2 + 3][i]
	for i in range(2, 9, 3):
		if i == 0 + 2:
			a[1 + 6][i] = a[0 + 6][i]
		elif i == 3 + 2:
			a[2 + 6][i] = a[1 + 6][i]
		else:
			a[0 + 6][i] = a[2 + 6][i]
	for i in a:
		print(''.join(i))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	l = []
	for i in range(9):
		x = str(input())
		x = x[:-1]
		if i == 8:
			x = x[:-1] + str(int(x[-1]) % 9 + 1)
		else:
			x = x[:3 * i % 8] + str(int(x[3 * i % 8]) % 9 + 1) + x[3 * i % 8 + 1:]
		l.append(x)
	for i in l:
		print(i)


for i in range(int(input())):
	for j in range(9):
		l = input()
		print(l.replace('1', '2'))


n = int(input())
for i in range(n):
	for j in range(9):
		s = str(input())
		s = s.replace('9', '8')
		print(s)


MOD = 10 ** 9 + 7

def main():
	test = int(input())
	for iteration in range(test):
		suduko = []
		for i in range(9):
			suduko.append(list(input()))
		suduko[0][1] = suduko[0][0]
		suduko[1][4] = suduko[1][3]
		suduko[2][7] = suduko[2][6]
		suduko[3][2] = suduko[3][1]
		suduko[4][5] = suduko[4][4]
		suduko[5][8] = suduko[5][7]
		suduko[6][0] = suduko[6][2]
		suduko[7][3] = suduko[7][5]
		suduko[8][6] = suduko[8][8]
		for i in suduko:
			for j in i:
				print(j, end='')
			print()
main()


from collections import defaultdict as dd
for _ in range(int(input())):
	l = []
	d = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	for i in range(9):
		l.append(list(input().strip()))
	l[0][0] = l[0][1]
	l[1][3] = l[1][4]
	l[2][6] = l[2][7]
	l[3][8] = l[3][7]
	l[4][4] = l[4][5]
	l[5][1] = l[5][2]
	l[6][2] = l[6][3]
	l[7][5] = l[7][6]
	l[8][7] = l[8][8]
	for i in range(9):
		print(''.join(l[i]))


from operator import itemgetter
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = [list(input()[:-1]) for i in range(9)]
	for i in range(9):
		for j in range(9):
			if s[i][j] == '1':
				s[i][j] = '2'
	for i in s:
		print(''.join(i))


for i in range(int(input())):
	r = 0
	for j in range(9):
		s = input()
		y = r + j % 3 * 3
		print(s[:y] + '1' + s[y + 1:] if s[y] != '1' else s[:y] + '2' + s[y + 1:])
		if j % 3 == 2:
			r += 1


pairs = [[0, 0], [3, 1], [6, 2], [1, 3], [4, 4], [7, 5], [2, 6], [5, 7], [8, 8]]
for _ in range(int(input())):
	L = []
	for i in range(9):
		L.append(list(input()))
	for i in pairs:
		if L[i[0]][i[1]] == '9':
			L[i[0]][i[1]] = '1'
		else:
			L[i[0]][i[1]] = str(int(L[i[0]][i[1]]) + 1)
	for i in L:
		S = ''.join(i)
		print(S)


import sys
input = sys.stdin.readline
cases = int(input())
for t in range(cases):
	for i in range(9):
		v = list(input())
		for j in range(9):
			if v[j] == '1':
				v[j] = '2'
		print(''.join(v))


t = int(input())
while t:
	row1 = input()
	row2 = input()
	row3 = input()
	row4 = input()
	row5 = input()
	row6 = input()
	row7 = input()
	row8 = input()
	row9 = input()
	val = int(row1[0])
	if val == 9:
		val = 1
	else:
		val += 1
	row1 = str(val) + row1[1:]
	val = int(row2[4])
	if val == 9:
		val = 1
	else:
		val += 1
	row2 = row2[:4] + str(val) + row2[5:]
	val = int(row3[8])
	if val == 9:
		val = 1
	else:
		val += 1
	row3 = row3[:8] + str(val) + row3[9:]
	val = int(row4[1])
	if val == 9:
		val = 1
	else:
		val += 1
	row4 = row4[:1] + str(val) + row4[2:]
	val = int(row5[5])
	if val == 9:
		val = 1
	else:
		val += 1
	row5 = row5[:5] + str(val) + row5[6:]
	val = int(row6[6])
	if val == 9:
		val = 1
	else:
		val += 1
	row6 = row6[:6] + str(val) + row6[7:]
	val = int(row7[2])
	if val == 9:
		val = 1
	else:
		val += 1
	row7 = row7[:2] + str(val) + row7[3:]
	val = int(row8[3])
	if val == 9:
		val = 1
	else:
		val += 1
	row8 = row8[:3] + str(val) + row8[4:]
	val = int(row9[7])
	if val == 9:
		val = 1
	else:
		val += 1
	row9 = row9[:7] + str(val) + row9[8:]
	print(row1)
	print(row2)
	print(row3)
	print(row4)
	print(row5)
	print(row6)
	print(row7)
	print(row8)
	print(row9)
	t -= 1


t = int(input())
for i in range(t):
	l = [list(input()) for i in range(9)]
	for k in range(9):
		for j in range(9):
			if l[k][j] == '1':
				l[k][j] = '2'
	for k in l:
		print(*k, sep='')


import sys
import math
from collections import defaultdict
mod = 1000000007
T = 1
T = int(sys.stdin.readline())
for _ in range(T):
	n = 9
	l = []
	for i in range(n):
		a = input()
		p = []
		for j in a:
			p.append(j)
		l.append(p)
	for i in range(n):
		for j in range(n):
			if l[i][j] == '1':
				l[i][j] = '9'
	for i in l:
		print(''.join(i))


s = ''
x = 0
c = 0
cases = int(input())
while cases > 0:
	while c < 3:
		while x < 9:
			s = input()
			if s[x + c] == '1':
				s = s.replace(s[x + c], '2')
			else:
				s = s.replace(s[x + c], '1')
			print(s)
			x += 3
		c += 1
		x = 0
	cases -= 1
	x = 0
	c = 0


for case in range(int(input())):
	sudoku = []
	for i in range(9):
		sudoku.append(list(input()))
		for j in range(9):
			if sudoku[i][j] == '1':
				sudoku[i][j] = '2'
	for i in range(9):
		print(''.join(sudoku[i]))


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return pow(10, 9) + 7

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
for _ in range(INI()):
	X = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	i = 0
	for (_, i) in zip(range(9), X):
		x = list(INS())
		if int(x[i]) != 9:
			x[i] = int(x[i]) + 1
		else:
			x[i] = 1
		i += 1
		print(*x, sep='', end='')


cases = int(input())
for _ in range(cases):
	s = [int(input()) for c in range(9)]
	for i in range(len(s)):
		lst = []
		while s[i]:
			lst.append(s[i] % 10)
			s[i] //= 10
		s[i] = lst[::-1]
	for i in range(9):
		idx = i % 3 * 3 + i // 3
		s[i][idx] = s[i][idx] + 1
		if s[i][idx] > 9:
			s[i][idx] -= 9
	for i in range(9):
		for j in s[i]:
			print(j, end='')
		print()


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	a = [[int(i) for i in input()] for j in range(9)]
	x = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		a[i][x[i]] = 10 - a[i][x[i]]
		if a[i][x[i]] == 5:
			a[i][x[i]] = 6
	for i in a:
		print(''.join(map(str, i)))


t = int(input())
tech = list(range(1, 10))
for i in range(t):
	sudo = []
	for i in range(9):
		sudo.append(list(input()))
	sudo[0][0] = str(tech[(int(sudo[0][0]) + 1) % len(tech)])
	sudo[1][3] = str(tech[(int(sudo[1][3]) + 1) % len(tech)])
	sudo[2][6] = str(tech[(int(sudo[2][6]) + 1) % len(tech)])
	sudo[3][1] = str(tech[(int(sudo[3][1]) + 1) % len(tech)])
	sudo[4][4] = str(tech[(int(sudo[4][4]) + 1) % len(tech)])
	sudo[5][7] = str(tech[(int(sudo[5][7]) + 1) % len(tech)])
	sudo[6][2] = str(tech[(int(sudo[6][2]) + 1) % len(tech)])
	sudo[7][5] = str(tech[(int(sudo[7][5]) + 1) % len(tech)])
	sudo[8][8] = str(tech[(int(sudo[8][8]) + 1) % len(tech)])
	for i in sudo:
		print(''.join(i))


from sys import stdin, stdout

def read():
	x0 = stdin.readline().rstrip()
	return x0

def __main__():
	t = int(read())
	for t0 in range(t):
		na = [read() for i in range(9)]
		ind_list = [0, 3, 6, 1, 4, 7, 2, 5, 8]
		ind = 0
		for n0 in na:
			nh = list(n0)
			if nh[ind_list[ind]] == '1':
				nh[ind_list[ind]] = '2'
			else:
				nh[ind_list[ind]] = '1'
			ind += 1
			out = ''.join(nh) + '\n'
			stdout.write(out)
__main__()


import sys, math, cmath, time
start_time = time.time()

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

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

def insr():
	s = input()
	return s[:len(s) - 1]

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

def qw(n):
	n = n + 1
	if n == 10:
		n = 8
	return str(n)

def solve():
	a = []
	for i in range(9):
		s = insr()
		a.append(list(s))
	a[0][0] = qw(int(a[0][0]))
	a[1][3] = qw(int(a[1][3]))
	a[2][6] = qw(int(a[2][6]))
	a[3][1] = qw(int(a[3][1]))
	a[4][4] = qw(int(a[4][4]))
	a[5][7] = qw(int(a[5][7]))
	a[6][2] = qw(int(a[6][2]))
	a[7][5] = qw(int(a[7][5]))
	a[8][8] = qw(int(a[8][8]))
	for i in range(9):
		print(*a[i], sep='')
	print()

def main():
	ONLINE_JUDGE = __debug__
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
	sys.stdout.close()

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q
input = sys.stdin.readline
main()


def sol():
	a1 = []
	for i in range(9):
		x = input()
		a1.append(x.replace('1', '2'))
	for i in a1:
		print(i)
for _ in range(int(input())):
	sol()


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		rows = [list(map(int, list(input()))) for _ in range(9)]
		for (k, m) in ((0, 0), (1, 4), (2, 8), (3, 1), (4, 5), (5, 6), (6, 2), (7, 3), (8, 7)):
			rows[k][m] = (rows[k][m] + 1) % 9 + 1
		for row in rows:
			print(''.join(map(str, row)))
	q = int(input())
	for _ in range(q):
		solve()
main()


from collections import defaultdict
t = int(input())
for _ in range(t):
	arr = []
	for i in range(9):
		y = [0] * 9
		arr.append(y)
	for i in range(9):
		s = input()
		for j in range(len(s)):
			arr[i][j] = s[j]
	arr[1][0] = arr[0][0]
	arr[0][3] = arr[1][3]
	arr[2][6] = arr[1][6]
	arr[4][1] = arr[3][1]
	arr[3][4] = arr[4][4]
	arr[5][7] = arr[4][7]
	arr[7][2] = arr[6][2]
	arr[6][5] = arr[7][5]
	arr[8][8] = arr[7][8]
	for i in range(9):
		for j in range(9):
			print(arr[i][j], end='')
		print()


for i in range(int(input())):
	sudoku = [list(map(int, input())) for j in range(9)]
	arr = [8, 5, 2, 7, 4, 1, 6, 3, 0]
	for j in range(9):
		if sudoku[arr[j]][j] == 8:
			sudoku[arr[j]][j] = 9
		else:
			sudoku[arr[j]][j] = (sudoku[arr[j]][j] + 1) % 9
	for j in range(9):
		for k in range(9):
			print(sudoku[j][k], end='')
		print()


def solve():
	l = []
	for i in range(9):
		l.append(input())
	for i in range(9):
		l[i] = l[i].replace('2', '1')
	for element in l:
		print(element)
t = int(input())
for loop in range(t):
	solve()


t = int(input())
for i in range(t):
	li = []
	for i in range(9):
		li.append(list(input()))
	for i in range(9):
		if i % 3 == 0:
			li[i][6 + i // 3] = li[i][6 + i // 3 - 1]
		elif i % 3 == 1:
			li[i][0 + i // 3] = li[i][0 + i // 3 - 1]
		else:
			li[i][3 + i // 3] = li[i][3 + i // 3 - 1]
	print()
	for i in range(9):
		s = ''
		s = s.join(li[i])
		print(s)


from math import gcd, ceil
from collections import defaultdict as dd

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

def inin():
	return int(input())

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

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def pred(n, k, pointer):
	return pointer - k >= n
for _ in range(inin()):
	ar = [[0 for i in range(9)] for j in range(9)]
	for i in range(9):
		s = input()
		ns = ''
		for k in s:
			if k == '2':
				ns += '1'
			else:
				ns += k
		ar[i] = ns
	for i in range(9):
		for j in range(9):
			print(ar[i][j], end='')
		print()


n = int(input())
for i in range(n):
	for x in range(9):
		f = int(x - x // 3 * 3 + x // 3 + (x - x // 3 * 3) * 2)
		s = str(input())
		if s[f] != '9':
			print(s.replace(s[f], '9'))
		else:
			print(s.replace(s[f], '1'))


def listToString(s):
	str1 = ''
	for ele in s:
		str1 += ele
	return str1
from math import *
from random import *
t = int(input())
for i in range(t):
	FILE = []
	for j in range(9):
		FILE.append(list(input()))
	l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	l1 = [[0, 0], [3, 1], [6, 2], [1, 3], [4, 4], [7, 5], [2, 6], [5, 7], [8, 8]]
	for j in range(len(l1)):
		num = choice(l)
		while int(FILE[l1[j][0]][l1[j][1]]) == num:
			num = choice(l)
		FILE[l1[j][0]][l1[j][1]] = str(num)
	FINALE = []
	for j in range(len(FILE)):
		FINALE.append(listToString(FILE[j]))
	for j in range(len(FINALE)):
		print(FINALE[j])


from collections import Counter as cou
for _ in range(int(input())):
	l = []
	for i in range(9):
		l.append(list(input()))
	l[0][1] = l[0][0]
	l[1][4] = l[1][3]
	l[2][7] = l[2][6]
	l[3][0] = l[3][1]
	l[4][3] = l[4][4]
	l[5][6] = l[5][7]
	l[6][2] = l[6][1]
	l[7][5] = l[7][4]
	l[8][8] = l[8][7]
	for i in range(9):
		temp = ''
		for j in range(9):
			temp += l[i][j]
		print(temp)


zzz = ''

def write(s):
	global zzz
	zzz += s
t = int(input())
for l in range(t):
	g = []
	for i in range(9):
		k = input()
		g.append([])
		for ele in k:
			g[i].append(int(ele))
	i = 0
	j = 0
	while i < 9:
		if j >= 9:
			j = j % 9 + 1
		m = (g[i][j] + 1) % 10
		if m == 0:
			m += 1
		g[i][j] = m
		i += 1
		j += 3
	for i in range(9):
		temp = ''
		for j in range(9):
			temp += str(g[i][j])
		print(temp)


for _ in range(int(input())):
	p = i = 0
	k = 1
	for g in range(9):
		a = list(input())
		if p == 2:
			if k:
				i = 3
				k = 0
				a[i - 1] = a[i - 2]
			else:
				i += 3
				a[i - 1] = a[i - 2]
			print(''.join(a))
		if p != 2:
			a[i] = a[i + 1]
			i += 3
			print(''.join(a))
		if p + 9 == i:
			p += 1
			i = p


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	for i in range(9):
		print(z().replace('9', '1', 9))


for i in range(int(input())):
	k = []
	for j in range(9):
		f = [int(_) for _ in input()]
		k.append(f)
	k[0][0] %= 9
	k[0][0] += 1
	k[1][3] %= 9
	k[1][3] += 1
	k[2][6] %= 9
	k[2][6] += 1
	k[3][1] %= 9
	k[3][1] += 1
	k[4][4] %= 9
	k[4][4] += 1
	k[5][7] %= 9
	k[5][7] += 1
	k[6][2] %= 9
	k[6][2] += 1
	k[7][5] %= 9
	k[7][5] += 1
	k[8][8] %= 9
	k[8][8] += 1
	for j in k:
		print(*j, sep='')


def soln(grid):
	for (r, c) in [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]:
		if grid[r][c] == 1:
			grid[r][c] = 2
		else:
			grid[r][c] = 1

def main():
	t = int(input())
	for _ in range(t):
		grid = []
		for _ in range(9):
			grid.append([int(c) for c in input()])
		soln(grid)
		print('\n'.join((''.join((str(x) for x in row)) for row in grid)))
main()


for _ in range(int(input())):
	l = []
	for i in range(9):
		C = []
		r = list(input())
		c1 = r[0:3]
		c2 = r[3:6]
		c3 = r[6:9]
		C.append(c1)
		C.append(c2)
		C.append(c3)
		l.append(C)
	for k in range(3):
		j = 0
		for i in range(k, 7 + k, 3):
			if i == k:
				l[i][k][j] = l[i][k][j + 1]
			else:
				l[i][k][j] = l[i][k][j - 1]
			j += 1
	for i in range(9):
		for j in range(3):
			for k in l[i][j]:
				print(k, end='')
		print()


def main():
	t = int(input())
	while t:
		t = t - 1
		li = []
		for i in range(9):
			li.append(list(map(str, input())))
		for i in range(3):
			for j in range(3):
				li[3 * i + j][i + 3 * j] = li[3 * i + j][(i + 3 * j + 1) % 9]
		for x in li:
			print(''.join(x))
main()


for _ in range(int(input())):
	Result = [list(input()) for i in range(9)]
	Result[0][1] = Result[0][0]
	Result[1][4] = Result[1][3]
	Result[2][7] = Result[2][6]
	Result[3][0] = Result[3][1]
	Result[4][3] = Result[4][4]
	Result[5][6] = Result[5][7]
	Result[6][2] = Result[6][1]
	Result[7][5] = Result[7][4]
	Result[8][8] = Result[8][7]
	for i in range(9):
		print(*Result[i], sep='')


for _ in range(int(input())):
	d = []
	for i in range(9):
		a = input()
		li = [int(j) for j in a]
		d.append(li)
	d[0][0] = d[1][0]
	d[3][1] = d[4][1]
	d[6][2] = d[7][2]
	d[0 + 1][0 + 3] = d[1 + 1][0 + 3]
	d[3 + 1][1 + 3] = d[4 + 1][1 + 3]
	d[6 + 1][2 + 3] = d[7 + 1][2 + 3]
	d[0 + 2][0 + 6] = d[1 + 2][0 + 6]
	d[3 + 2][1 + 6] = d[4 + 2][1 + 6]
	d[6 + 2][2 + 6] = d[0][2 + 6]
	for i in d:
		li = [str(j) for j in i]
		print(''.join(li))


t = int(input())
for _ in range(t):
	matrix = []
	for i in range(9):
		row = [i for i in input()]
		matrix.append(row)
	temp = 0
	for i in range(0, 9, 3):
		t1 = 0
		for j in range(0, 9, 3):
			if j + temp == 8:
				matrix[i + t1][j + temp] = matrix[i + t1][j + temp - 1]
			else:
				matrix[i + t1][j + temp] = matrix[i + t1][j + temp + 1]
			t1 += 1
		temp += 1
	for i in range(len(matrix)):
		matrix[i] = ''.join(matrix[i])
	for i in range(9):
		print(matrix[i])


import math
testCases = int(input())
for _ in range(testCases):
	for _ in range(9):
		print(input().replace('1', '2'))


import sys
for t in range(int(sys.stdin.readline())):
	sudoku = ['' for i in range(9)]
	for i in range(9):
		for ch in sys.stdin.readline():
			if ch == '6':
				sudoku[i] += '9'
			else:
				sudoku[i] += ch
	for row in sudoku:
		sys.stdout.write(row)


t = int(input())
for i in range(t):
	l = []
	for i in range(9):
		l.append(input())
	for i in l:
		thing = i.index('2')
		print(i[:thing] + '1' + i[thing + 1:])


def solve(grid):
	for i in range(9):
		grid[i] = grid[i].replace('1', '2')
	return '\n'.join(grid)
t = int(input())
for _ in range(t):
	grid = []
	for i in range(9):
		row = input()
		grid.append(row)
	print(solve(grid))


for _ in [0] * int(input()):
	for i in range(9):
		r = [*map(int, input())]
		j = i // 3 + i % 3 * 3
		r[j] = r[j] % 9 + 1
		print(*r, sep='')


for i in range(int(input())):
	l = []
	for j in range(9):
		x = input()
		x = list(x)
		for k in range(len(x)):
			if x[k] == '9':
				x[k] = '8'
		l.append(x)
	for m in l:
		print(''.join(m))


test = [[0, 0], [3, 1], [6, 2], [1, 3], [4, 4], [7, 5], [2, 6], [5, 7], [8, 8]]
for _ in range(int(input())):
	board = []
	for _ in range(9):
		board.append([int(i) for i in input()[:]])
	for i in range(9):
		if board[test[i][0]][test[i][1]] != 9:
			board[test[i][0]][test[i][1]] += 1
		else:
			board[test[i][0]][test[i][1]] = 1
	for line in board:
		string = ''
		for num in line:
			string += str(num)
		print(string)


n = int(input())
for i in range(n):
	arr = []
	for i in range(9):
		arr.append([int(j) for j in input()])
	seq = [0, 1, 2, 3, 4, 5, 6, 7, 8]
	seq2 = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for (i, j) in zip(seq, seq2):
		if arr[i][j] == 9:
			arr[i][j] = 1
		else:
			arr[i][j] = arr[i][j] + 1
	for i in arr:
		print(''.join((str(j) for j in i)))


def solve():
	j = 0
	for i in range(9):
		line = input()
		for j in range(len(line)):
			if line[j] == '3':
				line = line[:j] + '1' + line[j + 1:]
		print(line)
T = int(input())
while T > 0:
	solve()
	T -= 1


import sys
import os
from io import IOBase, BytesIO
import math
import collections
mod = 10 ** 9 + 7
pie = 3.1415926536

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def read2DIntArray(row, col):
	arr = []
	for i in range(0, row):
		temp = list(map(int, sin().split()))
		arr.append(temp)
	return arr

def read2DCharArray(row, col):
	arr = []
	for i in range(0, row):
		temp = str(sin())
		arr.append(temp)
	return arr

def smallestNumber(n):
	lst = list(str(n))
	lst.sort()
	tmp = ''
	for (i, n) in enumerate(lst):
		if n != '0':
			tmp = lst.pop(i)
			break
	return str(tmp) + ''.join(lst)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	lst = []
	for p in range(n + 1):
		if prime[p]:
			lst.append(p)
	return lst

def nCr(n, r):
	a = 1
	b = 1
	c = 1
	for i in range(1, n + 1):
		c *= i
	for i in range(1, r + 1):
		b *= i
	for i in range(1, n - r + 1):
		a *= i
	return c // (a * b)

def sieveOfEratosthenes1(N, s):
	prime = [False] * (N + 1)
	for i in range(2, N + 1, 2):
		s[i] = 2
	for i in range(3, N + 1, 2):
		if prime[i] == False:
			s[i] = i
			for j in range(i, int(N / i) + 1, 2):
				if prime[i * j] == False:
					prime[i * j] = True
					s[i * j] = i

def generatePrimeFactors(N):
	s = [0] * (N + 1)
	sieveOfEratosthenes1(N, s)
	curr = s[N]
	cnt = 1
	factors = []
	power = []
	while N > 1:
		N //= s[N]
		if curr == s[N]:
			cnt += 1
			continue
		factors.append(curr)
		power.append(cnt)
		curr = s[N]
		cnt = 1
	return (factors, power)

def main():
	for _ in range(int(sin())):
		lst = []
		for i in range(9):
			lst.append(sin())
		for i in range(9):
			tmp = list(lst[i])
			if i % 3 == 0:
				tmp[0 + int(i / 3)] = (int(tmp[0 + int(i / 3)]) + 1) % 9 + 1
			elif i % 3 == 1:
				tmp[3 + int(i / 3)] = (int(tmp[3 + int(i / 3)]) + 1) % 9 + 1
			elif i % 3 == 2:
				tmp[6 + int(i / 3)] = (int(tmp[6 + int(i / 3)]) + 4) % 9 + 1
			lst[i] = tmp
		for i in range(9):
			print(*lst[i], sep='')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


import sys

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

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a

def f(i, j):
	matr[i][j] = matr[i][j] + 1 if matr[i][j] <= 8 else 1
for __ in range(int(input())):
	matr = [[]] * 9
	for i in range(9):
		matr[i] = [int(j) for j in input()]
	f(0, 0)
	f(1, 3)
	f(2, 6)
	f(3, 1)
	f(4, 4)
	f(5, 7)
	f(6, 2)
	f(7, 5)
	f(8, 8)
	for i in range(9):
		s = ''
		for j in range(9):
			s += str(matr[i][j])
		print(s)


t = int(input())
s = []
dict = {0: 0, 1: 3, 2: 6, 3: 1, 4: 4, 5: 7, 6: 2, 7: 5, 8: 8}
for i in range(t):
	s = []
	for j in range(9):
		ss = input()
		s.append(ss)
	for j in range(9):
		if s[j][dict[j]] == '5':
			x = '6'
		else:
			x = '5'
		print(s[j][:dict[j]] + x + s[j][dict[j] + 1:])


for i in range(int(input())):
	a = []
	for i in range(9):
		s = input()
		c = []
		for j in range(9):
			c.append(int(s[j]))
		a.append(c)
	b = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		j = b[i]
		if a[i][j] == 5:
			a[i][j] = 6
		else:
			a[i][j] = 10 - a[i][j]
	for elem in a:
		for el in elem:
			print(el, end='')
		print()


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	a = [list(map(int, list(input()[:-1]))) for _ in range(9)]
	for i in range(9):
		for j in range(9):
			if a[i][j] == 1:
				a[i][j] = 2
	for ai in a:
		print(''.join(map(str, ai)))


import sys
input = sys.stdin.readline
from collections import *
from math import *
t = int(input())
ref = {'1': '2', '2': '3', '3': '4', '4': '5', '5': '6', '6': '7', '7': '8', '8': '9', '9': '1'}
while t:
	t -= 1
	r = []
	for i in range(9):
		r.append(input().rstrip())
	r11 = []
	r1 = ref[r[0][0]] + r[0][1:]
	r11.append(r1)
	r1 = r[1][:3] + ref[r[1][3]] + r[1][4:]
	r11.append(r1)
	r1 = r[2][:6] + ref[r[2][6]] + r[2][7:]
	r11.append(r1)
	r1 = r[3][:1] + ref[r[3][1]] + r[3][2:]
	r11.append(r1)
	r1 = r[4][:4] + ref[r[4][4]] + r[4][5:]
	r11.append(r1)
	r1 = r[5][:7] + ref[r[5][7]] + r[5][8:]
	r11.append(r1)
	r1 = r[6][:2] + ref[r[6][2]] + r[6][3:]
	r11.append(r1)
	r1 = r[7][:5] + ref[r[7][5]] + r[7][6:]
	r11.append(r1)
	r1 = r[8][:8] + ref[r[8][8]]
	r11.append(r1)
	for i in r11:
		print(i)


def list_to_str(liste):
	a = ''
	for i in liste:
		a = a + str(i)
	return a
for i in range(int(input())):
	matrix = []
	for i in range(9):
		arr = []
		for i in input():
			arr.append(i)
		matrix.append(arr)
	for i in matrix:
		for j in range(9):
			if i[j] == '1':
				i[j] = '2'
	for i in matrix:
		print(list_to_str(i))


import sys
input = sys.stdin.readline

def input_list():
	return map(int, input().split())
k = 9

def f():
	global k
	l = [[0] * k for _ in range(k)]
	for i in range(k):
		l[i] = [int(x) for x in input().strip()]
	for i in range(k):
		for j in range(k):
			if l[i][j] == 1:
				l[i][j] = 2
	for row in l:
		print(''.join((str(x) for x in row)))

def main():
	t = int(input())
	for _ in range(t):
		f()
main()


def solve(sudoko):
	for super_row in range(0, 3):
		used = {}
		restrict = [-1, -1, -1]
		for sub_col in range(0, 3):
			col = sub_col * 3 + super_row
			for sub_row in range(0, 3):
				row = super_row * 3 + sub_row
				if sudoko[row][col] == '9':
					restrict[sub_col] = sub_row
					break
		for i in range(0, 3):
			if restrict[i] != -1:
				restrict[i] = (restrict[i] + 1) % 3
				used[restrict[i]] = 1
		for i in range(0, 3):
			j = 0
			while j in used:
				j += 1
			if restrict[i] == -1:
				restrict[i] = j
				used[restrict[i]] = 1
		for sub_row in range(0, 3):
			row = super_row * 3 + restrict[sub_row]
			col = sub_row * 3 + super_row
			sudoko[row][col] = '9'
	for i in range(0, 9):
		print(''.join(sudoko[i]))
t = int(input())
for i in range(0, t):
	sudoko = []
	for j in range(0, 9):
		line = input()
		sudoko.append(list(line))
	solve(sudoko)


t = int(input())
for tt in range(t):
	sudoku = []
	for i in range(9):
		x = input()
		arr = []
		for j in x:
			arr.append(int(j))
		sudoku.append(arr)
	sudoku[0][0] = max(1, 9 - sudoku[0][0])
	sudoku[1][3] = max(9 - sudoku[1][3], 1)
	sudoku[2][6] = max(9 - sudoku[2][6], 1)
	sudoku[3][1] = max(9 - sudoku[3][1], 1)
	sudoku[4][4] = max(9 - sudoku[4][4], 1)
	sudoku[5][7] = max(9 - sudoku[5][7], 1)
	sudoku[6][2] = max(9 - sudoku[6][2], 1)
	sudoku[7][5] = max(9 - sudoku[7][5], 1)
	sudoku[8][8] = max(9 - sudoku[8][8], 1)
	for i in sudoku:
		for j in i:
			print(j, end='')
		print()


t = int(input())
for qwe in range(t):
	matr = [0] * 9
	for i in range(9):
		matr[i] = list(map(int, input()))
	for i in range(9):
		for j in range(9):
			if matr[i][j] == 1:
				matr[i][j] = 9
			print(matr[i][j], end='')
		print()


def change(ss):
	new_ss = []
	for s in ss:
		new_s = ''.join([c if c != '1' else '2' for c in s])
		new_ss.append(new_s)
	return new_ss
t = int(input())
for _ in range(t):
	ss = [input() for _ in range(9)]
	new_ss = change(ss)
	for s in new_ss:
		print(s)


t = int(input())
for _ in range(t):
	grid = []
	change = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	idx = 0
	for i in range(9):
		temp = list(map(int, list(input())))
		sec = change[idx] + 1
		if sec == 3:
			sec = 0
		elif sec == 6:
			sec = 3
		elif sec == 9:
			sec = 6
		temp[change[idx]] = temp[sec]
		idx += 1
		grid.append(temp)
	for i in grid:
		print(*i, sep='')


t = int(input())
for _ in range(t):
	sudoku = ['' for k in range(9)]
	for k in range(9):
		sudoku[k] = input()
	for r in range(9):
		c = r % 3 * 3 + r // 3
		if sudoku[r][c] != '1':
			sudoku[r] = sudoku[r][0:c] + '1' + sudoku[r][c + 1:]
		else:
			sudoku[r] = sudoku[r][0:c] + '2' + sudoku[r][c + 1:]
	for k in range(9):
		print(sudoku[k])


for _ in range(int(input())):
	mat = []
	for i in range(9):
		mat.append(list(input()))
	if mat[0][0] == '1':
		mat[0][0] = '2'
	else:
		mat[0][0] = '1'
	if mat[3][1] == '1':
		mat[3][1] = '2'
	else:
		mat[3][1] = '1'
	if mat[6][2] == '1':
		mat[6][2] = '2'
	else:
		mat[6][2] = '1'
	if mat[1][3] == '1':
		mat[1][3] = '2'
	else:
		mat[1][3] = '1'
	if mat[4][4] == '1':
		mat[4][4] = '2'
	else:
		mat[4][4] = '1'
	if mat[7][5] == '1':
		mat[7][5] = '2'
	else:
		mat[7][5] = '1'
	if mat[2][6] == '1':
		mat[2][6] = '2'
	else:
		mat[2][6] = '1'
	if mat[5][7] == '1':
		mat[5][7] = '2'
	else:
		mat[5][7] = '1'
	if mat[8][8] == '1':
		mat[8][8] = '2'
	else:
		mat[8][8] = '1'
	for i in mat:
		print(*i, sep='')
	print()


def find_min(diag):
	min_elem = ''
	for i in range(9):
		if not i in diag:
			min_elem = str(i)
	return min_elem
t = input()
for i in range(int(t)):
	m = []
	n = []
	diag = []
	for j in range(9):
		r = input()
		diag.append(r[(3 * j + int(j / 3)) % 9])
		m.append(r)
	min_elem = find_min(diag)
	for j in range(9):
		n.append('')
		for k in range(9):
			if k == (3 * j + int(j / 3)) % 9:
				if m[j][(3 * j + int(j / 3)) % 9] != min_elem:
					n[j] = n[j] + min_elem
				elif int(min_elem) + 1 != 10:
					n[j] = n[j] + str(int(min_elem) + 1)
				else:
					n[j] = n[j] + str(1)
			else:
				n[j] = n[j] + m[j][k]
		print(n[j])


def solveAll():
	nbCases = int(input())
	for _ in range(nbCases):
		case = readCase()
		print(solve(case))

def readCase():
	return [list(input()) for _ in range(9)]

def solve(grid):

	def changeCell(i, j):
		grid[i][j] = '2' if grid[i][j] == '1' else '1'
	changeCell(0, 0)
	changeCell(1, 3)
	changeCell(2, 6)
	changeCell(3, 1)
	changeCell(4, 4)
	changeCell(5, 7)
	changeCell(6, 2)
	changeCell(7, 5)
	changeCell(8, 8)
	return '\n'.join((''.join(row) for row in grid))
solveAll()


for _ in range(int(input())):
	for i in range(9):
		x = input()
		for k in range(9):
			if x[k] == '1':
				x = x[:k] + '2' + x[k + 1:]
		print(x)


T = int(input())
for _ in range(T):
	l = []
	change = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		s = list(input())
		if s[change[i]] == '1':
			s[change[i]] = '9'
		else:
			s[change[i]] = str(int(s[change[i]]) - 1)
		ans = ''.join(s)
		l.append(ans)
	for i in range(9):
		print(l[i])


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	a = []
	for i in range(9):
		s = input()
		s = list(s)
		a.append(s)
	for i in range(9):
		for j in range(9):
			if a[i][j] == '1':
				a[i][j] = '2'
	for i in range(9):
		print(*a[i], sep='')


for t in [*open(0)][1:]:
	print(t[:9].replace('1', '2'))


for _ in range(int(input())):
	graph = [0] * 9
	soln = [0] * 9
	for i in range(9):
		graph[i] = input()
		soln[i] = list(graph[i])
		if i == 0:
			soln[i][0] = graph[i][1]
		elif i == 1:
			soln[i][3] = graph[i][4]
		elif i == 2:
			soln[i][6] = graph[i][7]
		elif i == 3:
			soln[i][1] = graph[i][2]
		elif i == 4:
			soln[i][4] = graph[i][5]
		elif i == 5:
			soln[i][7] = graph[i][8]
		elif i == 6:
			soln[i][2] = graph[i][1]
		elif i == 7:
			soln[i][5] = graph[i][4]
		elif i == 8:
			soln[i][8] = graph[i][7]
	for i in range(9):
		soln[i] = ''.join(soln[i])
		print(soln[i])


T = int(input())
for t in range(T):
	board = []
	for i in range(9):
		board.append([int(x) for x in input()])
	if board[0][0] == 2:
		board[0][0] = 3
	else:
		board[0][0] = 2
	if board[1][3] == 2:
		board[1][3] = 3
	else:
		board[1][3] = 2
	if board[2][6] == 2:
		board[2][6] = 3
	else:
		board[2][6] = 2
	if board[3][1] == 2:
		board[3][1] = 3
	else:
		board[3][1] = 2
	if board[4][4] == 2:
		board[4][4] = 3
	else:
		board[4][4] = 2
	if board[5][7] == 2:
		board[5][7] = 3
	else:
		board[5][7] = 2
	if board[6][2] == 2:
		board[6][2] = 3
	else:
		board[6][2] = 2
	if board[7][5] == 2:
		board[7][5] = 3
	else:
		board[7][5] = 2
	if board[8][8] == 2:
		board[8][8] = 3
	else:
		board[8][8] = 2
	for s in board:
		print(''.join([str(y) for y in s]))


from typing import List

def read():
	a = []
	for i in range(9):
		a.append(input())
	return a

def solve(a: List[str]):
	for i in range(9):
		a[i] = a[i].replace('2', '1')
	return a
for t in range(int(input())):
	result = solve(read())
	print(*result, sep='\n')


for _ in range(int(input())):
	l = [[0 for i in range(9)] for j in range(9)]
	for i in range(9):
		s = input()
		for j in range(9):
			l[i][j] = int(s[j])
	a = b = 0
	for i in range(9):
		if i == 3:
			a = 1
		if i == 6:
			a = 2
		if 10 - l[a % 9][b % 9] == 5:
			l[a % 9][b % 9] = 6
		elif 10 - l[a % 9][b % 9] == 6:
			l[a % 9][b % 9] = 5
		else:
			l[a % 9][b % 9] = 10 - l[a % 9][b % 9]
		a += 3
		b += 1
	for i in range(9):
		s = ''
		for j in range(9):
			s += str(l[i][j])
		print(s)


from sys import stdin, exit
from bisect import *
from heapq import heappush, heappop
from itertools import combinations
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	grid = []
	for i in range(9):
		grid.append(list(map(int, list(si()))))
	grid[0][0] += 1
	grid[1][3] += 1
	grid[2][6] += 1
	grid[3][1] += 1
	grid[4][4] += 1
	grid[5][7] += 1
	grid[6][2] += 1
	grid[7][5] += 1
	grid[8][8] += 1
	for i in grid:
		for j in i:
			if j == 10:
				print(1, end='')
			else:
				print(j, end='')
		print()


for _ in range(int(input())):
	su = [input() for i in range(9)]
	for i in range(9):
		j = su[i].find('9')
		print(su[i][:j] + '1' + su[i][j + 1:])


t = int(input())
for i in range(t):
	for j in range(9):
		string = input().replace('1', '9')
		print(string)


t = int(input())
while t:
	col = []
	l = []
	for i in range(9):
		s = list(map(int, input()))
		l.append(s)
	for i in range(9):
		for j in range(9):
			if l[i][j] == 1:
				l[i][j] = 2
	for i in l:
		print(''.join((str(j) for j in i)))
	t -= 1


st = ''

def func():
	for i in l:
		one = i.index('1')
		i[one] = '2'
	s = ''
	for i in l:
		for j in i:
			s += j
		s += '\n'
	return s
t = int(input())
for _ in range(t):
	l = []
	for i in range(9):
		l.append(list(input()))
	st += str(func())
print(st)


from sys import stdin
from collections import defaultdict
t = int(stdin.readline())
for _ in range(t):
	grid = []
	for i in range(9):
		ip = stdin.readline().rstrip().replace('1', '2')
		print(ip)


for _ in range(int(input())):
	arr = []
	for i in range(9):
		s = input()
		arr.append(list(map(int, list(s))))
	for i in range(3):
		for j in range(3):
			x = i * 3 + j
			y = j * 3 + i
			arr[x][y] = (arr[x][y] + 1) % 10
			if arr[x][y] == 0:
				arr[x][y] += 1
	for a in arr:
		print(*a, sep='')


t = int(input())
for _ in range(t):
	mat = []
	for _ in range(9):
		mat.append(list(input()))
	for row in range(9):
		for col in range(9):
			if mat[row][col] == '1':
				new_col = col
				if col in [2, 5, 8]:
					new_col = col // 3 * 3
				else:
					new_col += 1
				mat[row][new_col] = '1'
				break
	for row in mat:
		print(''.join(row))


def convertArrayToInt(A):
	for i in range(0, len(A), 1):
		A[i] = int(A[i])
	return A
testCases = int(input())

def makeAntiSudoku(matrix):
	col = 0
	for row in range(0, 9, 1):
		if row == 8 and col == 8:
			matrix[row][col] = matrix[row][0]
			break
		matrix[row][col] = matrix[row][col + 1]
		col = col + 3
		if col == 9:
			col = 1
		if col > 9:
			col = col % 8
	for i in range(0, 9, 1):
		for j in range(0, 9, 1):
			print(matrix[i][j], end='')
		print()

def split(word):
	return [char for char in word]
while testCases:
	matrix = []
	n = 9
	while n > 0:
		X = input()
		X = split(X)
		matrix.append(X)
		n -= 1
	makeAntiSudoku(matrix)
	testCases -= 1


def main():
	for _ in range(int(input())):
		table = [list(input()) for i in range(9)]
		table[0][0] = '1' if table[0][0] != '1' else '2'
		table[3][1] = '1' if table[3][1] != '1' else '2'
		table[6][2] = '1' if table[6][2] != '1' else '2'
		table[1][3] = '1' if table[1][3] != '1' else '2'
		table[4][4] = '1' if table[4][4] != '1' else '2'
		table[7][5] = '1' if table[7][5] != '1' else '2'
		table[2][6] = '1' if table[2][6] != '1' else '2'
		table[5][7] = '1' if table[5][7] != '1' else '2'
		table[8][8] = '1' if table[8][8] != '1' else '2'
		print('\n'.join((''.join(element) for element in table)))
main()


for _ in range(int(input())):
	mat = []
	for i in range(9):
		mat.append(input())
	for i in range(9):
		for j in mat[i]:
			if j == '1':
				mat[i] = mat[i].replace('1', '2')
	for i in range(9):
		print(mat[i])


for _ in range(int(input())):
	for __ in range(9):
		print(input().replace('6', '9'))


def main():
	array = []
	for i in range(9):
		array.append([int(idx) for idx in input()])
	i = 0
	j = 0
	while i < 9:
		if array[i][j] == 5:
			array[i][j] = 6
		else:
			array[i][j] = 10 - array[i][j]
			i += 1
			j += 3
			if j > 8:
				j -= 8
	for idx in array:
		print(*idx, sep='')
test_case = input()
for i in range(int(test_case)):
	main()


t = int(input())
for i in range(t):
	matrix = list()
	for j in range(9):
		err = str(input())
		arr = list()
		for h in range(len(err)):
			arr.append(ord(err[h]) - ord('0'))
		matrix.append(arr)
	matrix[0][0] += 1
	if matrix[0][0] == 10:
		matrix[0][0] = 1
	matrix[3][1] += 1
	if matrix[3][1] == 10:
		matrix[3][1] = 1
	matrix[6][2] += 1
	if matrix[6][2] == 10:
		matrix[6][2] = 1
	matrix[1][3] += 1
	if matrix[1][3] == 10:
		matrix[1][3] = 1
	matrix[4][4] += 1
	if matrix[4][4] == 10:
		matrix[4][4] = 1
	matrix[7][5] += 1
	if matrix[7][5] == 10:
		matrix[7][5] = 1
	matrix[2][6] += 1
	if matrix[2][6] == 10:
		matrix[2][6] = 1
	matrix[5][7] += 1
	if matrix[5][7] == 10:
		matrix[5][7] = 1
	matrix[8][8] += 1
	if matrix[8][8] == 10:
		matrix[8][8] = 1
	for j in matrix:
		print(*j, sep='')


t = int(input())
for i in range(t):
	r = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	k = 0
	for i in range(9):
		a = list(input())
		for j in range(9):
			if j == r[k]:
				if int(a[j]) == 1:
					print('9', end='')
				else:
					print('1', end='')
			else:
				print(a[j], end='')
		print()
		k += 1


t = int(input())
for i in range(t):
	l = []
	for j in range(9):
		n = input()
		a = []
		for k in range(len(n)):
			a.append(int(n[k]))
		l.append(a)
	if l[0][0] != 9:
		l[0][0] += 1
	else:
		l[0][0] = 1
	if l[3][1] != 9:
		l[3][1] += 1
	else:
		l[3][1] = 1
	if l[6][2] != 9:
		l[6][2] += 1
	else:
		l[6][2] = 1
	if l[2][6] != 9:
		l[2][6] += 1
	else:
		l[2][6] = 1
	if l[1][3] != 9:
		l[1][3] += 1
	else:
		l[1][3] = 1
	if l[4][4] != 9:
		l[4][4] += 1
	else:
		l[4][4] = 1
	if l[7][5] != 9:
		l[7][5] += 1
	else:
		l[7][5] = 1
	if l[5][7] != 9:
		l[5][7] += 1
	else:
		l[5][7] = 1
	if l[8][8] != 9:
		l[8][8] += 1
	else:
		l[8][8] = 1
	for j in range(9):
		for k in range(9):
			print(l[j][k], end='')
		print()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		dog = []
		for i in range(9):
			kap = list(input())
			dog.append(kap)
		dog[0][0] = dog[0][1]
		dog[1][3] = dog[1][4]
		dog[2][6] = dog[2][7]
		dog[3][1] = dog[3][2]
		dog[4][4] = dog[4][5]
		dog[5][7] = dog[5][8]
		dog[6][2] = dog[6][3]
		dog[7][5] = dog[7][6]
		dog[8][8] = dog[8][0]
		for i in range(9):
			yield ''.join((str(x) for x in dog[i]))
t = int(input())
ans = gift()
print(*ans, sep='\n')


for _ in range(int(input())):
	A = []
	for _ in range(9):
		A.append(list(map(int, input())))
	for i in range(3):
		A[3 * i + 0][i] = max(1, (A[3 * i + 0][i] + 1) % 10)
		A[3 * i + 1][i + 3] = max(1, (A[3 * i + 1][i + 3] + 1) % 10)
		A[3 * i + 2][i + 6] = max(1, (A[3 * i + 2][i + 6] + 1) % 10)
	for row in A:
		print(''.join([str(a) for a in row]))


import sys
t = int(sys.stdin.readline())
for i in range(t):
	arr = []
	for g in range(9):
		s = sys.stdin.readline().strip()
		tmp = []
		for x in range(9):
			tmp.append(s[x])
		arr.append(tmp)
	arr[0][1] = arr[0][0]
	arr[1][4] = arr[1][3]
	arr[2][7] = arr[2][6]
	arr[3][2] = arr[3][1]
	arr[4][5] = arr[4][4]
	arr[5][8] = arr[5][7]
	arr[6][0] = arr[6][2]
	arr[7][3] = arr[7][5]
	arr[8][6] = arr[8][8]
	for e in range(9):
		print(''.join(arr[e]))


t = int(input())
for i in range(t):
	l1 = list(input())
	l2 = list(input())
	l3 = list(input())
	l4 = list(input())
	l5 = list(input())
	l6 = list(input())
	l7 = list(input())
	l8 = list(input())
	l9 = list(input())
	if l1[0] == '5':
		l1[0] = '6'
	else:
		l1[0] = '5'
	if l2[3] == '5':
		l2[3] = '6'
	else:
		l2[3] = '5'
	if l3[6] == '5':
		l3[6] = '6'
	else:
		l3[6] = '5'
	if l4[1] == '5':
		l4[1] = '6'
	else:
		l4[1] = '5'
	if l5[4] == '5':
		l5[4] = '6'
	else:
		l5[4] = '5'
	if l6[7] == '5':
		l6[7] = '6'
	else:
		l6[7] = '5'
	if l7[2] == '5':
		l7[2] = '6'
	else:
		l7[2] = '5'
	if l8[5] == '5':
		l8[5] = '6'
	else:
		l8[5] = '5'
	if l9[8] == '5':
		l9[8] = '6'
	else:
		l9[8] = '5'
	print(''.join(l1))
	print(''.join(l2))
	print(''.join(l3))
	print(''.join(l4))
	print(''.join(l5))
	print(''.join(l6))
	print(''.join(l7))
	print(''.join(l8))
	print(''.join(l9))


t = int(input())
for _ in range(t):
	l = []
	for i in range(9):
		a = input()
		m = [int(a[i]) for i in range(9)]
		l.append(m)
	l[0][0] = l[1][0]
	l[1][3] = l[2][3]
	l[2][6] = l[1][7]
	l[3][1] = l[4][1]
	l[4][4] = l[5][4]
	l[5][7] = l[4][8]
	l[6][2] = l[7][2]
	l[7][5] = l[7][6]
	l[8][8] = l[6][6]
	for i in l:
		for j in i:
			print(j, end='')
		print()


t = int(input())
for i in range(0, t):
	a = []
	k = 0
	for j in range(0, 9):
		a.append(input())
		a[j] = list(a[j])
		if a[j][k % 9] != '9':
			a[j][k % 9] = str(int(a[j][k % 9]) + 1)
			k += 4
		else:
			a[j][k % 9] = '1'
			k += 4
	for j in range(0, 9):
		for tyu in range(0, 9):
			print(a[j][tyu], end='')
		print('')


t = int(input())
for _ in range(t):
	arr = []
	for i in range(9):
		arr.append(list(input().strip()))
	for (i, j) in [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]:
		num = int(arr[i][j])
		if 1 < num <= 9:
			num -= 1
		else:
			num += 2
		arr[i][j] = str(num)
	for rw in arr:
		print(''.join(rw))


from math import gcd
from collections import Counter

def printYes():
	print('YES')

def printNo():
	print('NO')

def a(b):
	b = int(b)
	b = b + 1
	if b > 9:
		b = 1
	return str(b)
t = int(input())
for i in range(t):
	l = []
	for i in range(9):
		l.append(list(input()))
	l[0][0] = a(l[0][0])
	l[1][3] = a(l[1][3])
	l[2][6] = a(l[2][6])
	l[3][1] = a(l[3][1])
	l[4][4] = a(l[4][4])
	l[5][7] = a(l[5][7])
	l[6][2] = a(l[6][2])
	l[7][5] = a(l[7][5])
	l[8][8] = a(l[8][8])
	for i in range(9):
		print(''.join(l[i]))


for i in range(int(input())):
	l = []
	for j in range(9):
		s = str(input())
		l1 = []
		for k in range(9):
			l1.append(s[k])
		l.append(l1)
	for j in range(9):
		for k in range(9):
			if l[j][k] == str(1):
				l[j][k] = str(2)
				break
	for j in range(9):
		print(''.join(l[j]))


for _ in range(int(input())):
	for p in range(9):
		row = list(input())
		for j in range(9):
			if row[j] == '9':
				print('8', end='')
			else:
				print(row[j], end='')
		print()


t = int(input())
for i in range(t):
	for j in range(9):
		a = input()
		print(a.replace('1', '5'))


t = int(input())
for ti in range(t):
	ns = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		s = input()
		print(s[:ns[i]] + str(int(s[ns[i]]) % 9 + 1) + s[ns[i] + 1:])


def solve():
	l = []
	for _ in range(9):
		s = input()
		temp = list(s)
		l.append(temp)
	for i in range(9):
		for j in range(9):
			if l[i][j] == '1':
				l[i][j] = '2'
	for i in range(9):
		s = ''
		for j in range(9):
			s += l[i][j]
		print(s)
try:
	for _ in range(int(input())):
		solve()
except:
	pass


import sys

def main():
	test_cases = int(sys.stdin.readline())
	for test_case in range(test_cases):
		raw_input = []
		for i in range(9):
			raw_input.append(sys.stdin.readline())
		sedoku_board = [[[[0 for i in range(3)] for j in range(3)] for k in range(3)] for l in range(3)]
		for i in range(9):
			for j in range(9):
				outer_row = int(i / 3)
				outer_col = int(j / 3)
				inner_row = int(i % 3)
				inner_col = int(j % 3)
				sedoku_board[outer_row][outer_col][inner_row][inner_col] = raw_input[i][j]
		for i in range(3):
			sedoku_board[0][i][i][1] = sedoku_board[0][i][i][0]
		for i in range(3):
			sedoku_board[1][i][i][2] = sedoku_board[1][i][i][1]
		for i in range(3):
			sedoku_board[2][i][i][0] = sedoku_board[2][i][i][2]
		for i in range(9):
			line = ''
			for j in range(9):
				outer_row = int(i / 3)
				outer_col = int(j / 3)
				inner_row = int(i % 3)
				inner_col = int(j % 3)
				line += sedoku_board[outer_row][outer_col][inner_row][inner_col]
			print(line)
main()


t = int(input())
for x in range(t):
	s = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	l = []
	for i in range(9):
		l.append(list(map(int, list(input()))))
	temp = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for j in range(9):
		i = temp[j]
		t = l[i][j]
		l[i][j] = s[t - 2]
	for i in range(9):
		for j in range(9):
			print(l[i][j], end='')
		print()


cases = int(input())
for cse in range(cases):
	c = 0
	for r in range(0, 9):
		ln = input()
		num = int(ln[c])
		res = ''
		for i in range(0, len(ln)):
			if i == c:
				if num == 9:
					res += '1'
				else:
					res += str(num + 1)
			else:
				res += ln[i]
		print(res)
		c = (c + 3) % 8
		if c == 0:
			c = 8


y = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for _ in range(int(input())):
	a = [[int(x) for x in input()[:9]] for _ in range(9)]
	for (i, j) in zip(range(9), y):
		a[i][j] = 1 if a[i][j] == 9 else a[i][j] + 1
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


t = int(input())
for _ in range(t):
	sudoku = [input().replace('2', '1') for _ in range(9)]
	print('\n'.join(sudoku))


import sys
input = sys.stdin.readline
from math import *
t = int(input())
while t > 0:
	t -= 1
	a = []
	for i in range(9):
		p = list(input().rstrip())
		for ii in range(9):
			p[ii] = int(p[ii])
		a.append(p)
	c = [i + 1 for i in range(9)]
	flag = [0 for i in range(10)]
	defr = [[] for i in range(9)]
	defb = [[] for i in range(9)]
	defc = [[] for i in range(9)]
	j = 0
	i = 0
	n = 9
	for ik in range(3):
		if ik != 0:
			i += 4
		for k in range(3):
			for ii in range(9):
				if a[i % 9][j % 9] != ii + 1 and ii + 1 not in defr[i % n] and (ii + 1 not in defr[j % n]) and (ii + 1 not in defr[(i + j) % 3]):
					defr[i % n].append(a[i % 9][j % 9])
					defc[j % n].append(a[i % 9][j % 9])
					defb[(i + j) % 3].append(a[i % 9][j % 9])
					a[i % 9][j % 9] = ii + 1
					break
			i += 3
			j += 1
	for i in range(9):
		print(*a[i], sep='')


t = int(input())
while t != 0:
	k = 9
	C = []
	while k != 0:
		A = list(map(int, input()))
		C.append(A)
		k -= 1
	C[0][0] = C[0][-1]
	C[1][3] = C[1][-1]
	C[2][6] = C[2][-1]
	C[3][1] = C[3][-1]
	C[4][4] = C[4][-1]
	C[5][7] = C[5][-1]
	C[6][2] = C[6][-1]
	C[7][5] = C[7][-1]
	C[8][8] = C[8][0]
	for x in C:
		print(*x, sep='')
	t -= 1


t = int(input())
while t > 0:
	arr = []
	for i in range(9):
		arr.append(list(map(int, list(input()))))
	k = 0
	for i in range(9):
		if i % 3 == 0:
			j = 0
			j += k
			k += 1
		if arr[i][j] != 2:
			arr[i][j] = 2
		else:
			arr[i][j] = 1
		j += 3
	for i in arr:
		i = list(map(str, i))
		print(''.join(i))
	t -= 1


for _ in range(int(input())):
	for i in range(0, 9):
		s = list(input())
		k = i % 3
		if i // 3 == 0:
			s[k * 3] = str(int(s[k * 3]) % 9 + 1)
		elif i // 3 == 1:
			s[k * 3 + 1] = str(int(s[k * 3 + 1]) % 9 + 1)
		else:
			s[k * 3 + 2] = str(int(s[k * 3 + 2]) % 9 + 1)
		for i in s:
			print(i, end='')
		print()


for _ in range(int(input())):
	mat = []
	for _ in range(9):
		mat.append(list(input()))
	k = 0
	l = 1
	for i in range(9):
		for j in range(1, 10):
			if int(mat[i][k]) != j:
				mat[i][k] = str(j)
				if k + 3 <= 8:
					k += 3
				else:
					k = l
					l += 1
				break
	for i in mat:
		print(*i, sep='')


t = int(input())
for _ in range(t):
	sud = list()
	for i in range(9):
		sud.append(str(input()))
	for i in range(3):
		for j in range(3):
			if i < 2:
				sud[i + j * 3] = sud[i + j * 3][:j + i * 3] + sud[i + j * 3 + 1][j + i * 3] + sud[i + j * 3][j + i * 3 + 1:]
			else:
				sud[i + j * 3] = sud[i + j * 3][:j + i * 3] + sud[i + j * 3 - 1][j + i * 3] + sud[i + j * 3][j + i * 3 + 1:]
	for i in range(9):
		print(sud[i])


from math import gcd, ceil, log
from collections import Counter, deque
from heapq import heappush, heappop, heapify

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

def arp(arr):
	return ''.join(arr)
for _ in range(int(input())):
	arr = []
	for _ in range(9):
		s = list(input())
		arr.append(s)
	for i in range(9):
		one = arr[i].index('1')
		nine = arr[i].index('9')
		arr[i][one] = arr[i][nine]
	for i in arr:
		print(arp(i))


import math

def main():
	arr = []
	for _ in range(9):
		arr.append(list(str(input())))
	for i in range(9):
		for j in range(9):
			if arr[i][j] == '1':
				arr[i][j] = '8'
	for i in range(9):
		print(''.join(arr[i]))
t = int(input())
while t:
	main()
	t -= 1


def f(data):
	lines = [0, 3, 6]
	c = 0
	for l in lines:
		data[l][c] = data[l][c + 1] if c < 2 else data[l][c - 1]
		data[l + 1][c + 3] = data[l + 1][c + 4] if c < 2 else data[l + 1][c + 2]
		data[l + 2][c + 6] = data[l + 2][c + 7] if c < 2 else data[l][c + 5]
		c += 1
	for d in data:
		print(''.join(map(str, d)))
T = int(input())
for _ in range(T):
	data = []
	for i in range(9):
		dt = list(map(int, list(input())))
		data.append(dt)
	f(data)


for _ in range(int(input())):
	sudoku = []
	for i in range(9):
		sudoku.append(list(map(str, list(input()))))
	sudoku[0][1] = sudoku[0][0]
	sudoku[1][4] = sudoku[1][3]
	sudoku[2][7] = sudoku[2][6]
	sudoku[3][6] = sudoku[2][6]
	sudoku[4][0] = sudoku[3][0]
	sudoku[5][3] = sudoku[3][3]
	sudoku[6][8] = sudoku[5][8]
	sudoku[7][2] = sudoku[6][2]
	sudoku[8][5] = sudoku[6][5]
	for i in range(9):
		print(''.join(sudoku[i]))


for i in range(int(input())):
	for i in range(9):
		print(input().replace('1', '2'))


for _ in range(int(input())):
	s = [input() for _ in range(9)]
	x = []
	r = ''
	for (i, j) in [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]:
		r = s[i][j]
		y = ''
		for p in range(9):
			if s[i][p] in s[i] and s[i][p] != r:
				y = s[i][p]
				break
		x.append(s[i][:j] + y + s[i][j + 1:])
	for i in x:
		print(i)


T = int(input())
for t in range(T):
	for j in range(3):
		for i in range(3):
			L = [int(k) - 1 for k in input()]
			L[i * 3 + j] = (L[i * 3 + j] + 1) % 9
			print(''.join([str(k + 1) for k in L]))


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():

	def change(y, x):
		if s[y][x] == 9:
			s[y][x] = 1
		else:
			s[y][x] = 9
	t = I()
	for _ in range(t):
		s = [list(map(int, input())) for i in range(9)]
		change(1, 1)
		change(2, 5)
		change(0, 6)
		change(4, 2)
		change(5, 4)
		change(3, 8)
		change(7, 0)
		change(8, 3)
		change(6, 7)
		for i in s:
			print(*i, sep='')
	return
solve()


tests = int(input())
for _ in range(tests):
	board = []
	for i in range(9):
		board.append(list(input()))
	to_change = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for c in to_change:
		board[c[0]][c[1]] = (int(board[c[0]][c[1]]) + 1) % 9 + 1
	for line in board:
		for cell in line:
			print(cell, end='')
		print()


t = int(input())

def solve(mat):
	ids = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for i in ids[:-1]:
		(a, b) = i
		mat[a][b] = mat[a][b + 1]
	mat[8][8] = mat[8][1]
	for i in range(9):
		print(''.join(mat[i]))
for _ in range(t):
	mat = [''] * 9
	for i in range(9):
		mat[i] = [ch for ch in str(input())]
	solve(mat)


t = int(input())
s = (0, 3, 6, 1, 4, 7, 2, 5, 8)
for _ in range(t):
	for i in s:
		a = list(input())
		a[i] = '1' if a[i] != '1' else '2'
		print(''.join(a))


for _ in range(int(input())):
	sudoku = []
	for i in range(9):
		sudoku.append(list(map(int, list(input()))))
	positions = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for pos in positions:
		temp = sudoku[pos[0]][pos[1]]
		if temp == 9:
			sudoku[pos[0]][pos[1]] = 1
		else:
			sudoku[pos[0]][pos[1]] += 1
	for i in range(9):
		print(''.join(map(str, sudoku[i])))


t = int(input())
for i in range(0, t):
	for j in range(0, 9):
		x = list(input())
		for l in range(0, len(x)):
			if x[l] == '2':
				x[l] = '3'
			print(x[l], end='')
		print('')


from textwrap import wrap

def test(mat):
	(x, y, z) = (0, 3, 6)
	for i in range(9):
		if i % 3 == 0:
			mat[i][x] = mat[i][i + 1]
		elif i % 3 == 1:
			mat[i][y] = mat[i][i + 1]
		else:
			mat[i][z] = mat[i][i - 1]
			x += 1
			y += 1
			z += 1
		mat[i] = [str(x) for x in mat[i]]
	s = [''.join(x) for x in mat]
	for i in s:
		print(i)
from textwrap import wrap
for i in range(int(input())):
	(k, l, m) = (-1, 2, 5)
	for j in range(9):
		x = input()
		rem = j % 3
		if rem == 0:
			x = x.replace(x[k + 1], x[k + 2])
		elif rem == 1:
			x = x.replace(x[l + 1], x[l + 2])
		else:
			x = x.replace(x[m + 1], x[m - 2])
			k += 1
			l += 1
			m += 1
		print(x)


t = int(input())
for _ in range(t):
	a = []
	for i in range(9):
		a.append(list(map(int, list(input()))))
	for i in range(3):
		x = a[i * 3][i]
		y = a[i * 3 + 1][i + 3]
		z = a[i * 3 + 2][i + 6]
		for j in range(1, 10):
			if (j - x) * (j - y) * (j - z) != 0:
				break
		a[i * 3][i] = j
		a[i * 3 + 1][i + 3] = j
		a[i * 3 + 2][i + 6] = j
	for i in range(9):
		print(*a[i], sep='')


import sys
from collections import Counter
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

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

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(M):
	v = [(0, 0), (1, 4), (2, 8), (3, 3), (4, 7), (5, 2), (6, 6), (7, 1), (8, 5)]
	M = [[int(c) for c in r] for r in M]
	for (i, j) in v:
		M[i][j] += 1
		if M[i][j] == 10:
			M[i][j] = 1
	return '\n'.join((''.join(map(str, r)) for r in M))

def main():
	T = read_int()
	for _ in range(T):
		M = [read_str() for _ in range(9)]
		print(slv(M))
main()


for _ in range(int(input())):
	for _ in range(9):
		row = list(input())
		for i in range(9):
			if row[i] == '2':
				row[i] = '1'
		print(''.join(row))


import math
x = int(input())
for _ in range(x):
	n = [[int(el) for el in input()] for _ in range(9)]
	for f in range(9):
		for h in range(9):
			if n[f][h] == 8:
				n[f][h] = 1
	for u in n:
		for t in u:
			print(t, end='')
		print()


Q = int(input())
for q in range(Q):
	s = [input().replace('2', '1') for i in range(9)]
	for i in s:
		print(i)


for t in range(int(input())):
	y = []
	for i in range(9):
		y.append(list(input()))
	for i in range(9):
		for j in range(9):
			if y[i][j] == '2':
				y[i][j] = '1'
	for l in y:
		print(''.join(l))


for _ in range(int(input())):
	mat = []
	for i in range(9):
		l = [x for x in input()]
		mat += [l]
	for i in range(3):
		for j in range(3):
			if int(mat[i * 3 + j][j * 3 + i]) < 8:
				mat[i * 3 + j][j * 3 + i] = str(int(mat[i * 3 + j][j * 3 + i]) + 1)
			else:
				mat[i * 3 + j][j * 3 + i] = str(int(mat[i * 3 + j][j * 3 + i]) - 1)
	for i in mat:
		print(''.join(i))


from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		aa = [list(SI()) for _ in range(9)]
		j = 0
		for i in range(9):
			aa[i][j] = aa[i][(j + 1) % 9]
			j += 3
			if j >= 9:
				j = (j + 1) % 9
		for row in aa:
			print(''.join(row))
main()


from collections import defaultdict, deque
from itertools import permutations, product, combinations
from functools import lru_cache
from time import time
import sys
from operator import itemgetter
start = time()

def show_time():
	print(time() - start, file=sys.stderr)
try:
	f = open('test.in')

	def ints():
		return map(int, f.readline().strip().split())

	def one_int():
		return int(f.readline())

	def one_string():
		return f.readline().strip()

	def strings():
		return f.readline().strip().split()
except FileNotFoundError:

	def ints():
		return map(int, input().strip().split())

	def one_int():
		return int(input())

	def one_string():
		return input().strip()

	def strings():
		return input().strip().split()

def debug(s):
	print(s, file=sys.stderr)
sys.stderr.write('\n')

def warp(s, i):
	r = ''
	changed = [(0, 0), (1, 4), (2, 8), (3, 1), (4, 5), (5, 7), (6, 2), (7, 3), (8, 6)]
	for (j, ch) in enumerate(list(s)):
		if (i, j) in changed:
			r += str(int(ch) % 9 + 1)
		else:
			r += ch
	assert len(set(list(r))) < 9
	return r
t = one_int()
for _ in range(t):
	for i in range(9):
		s = one_string()
		print(warp(s, i))


t = int(input())
for _ in range(t):
	s = [input() for i in range(9)]
	p = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for (i, j) in p:
		v = s[i][j]
		s[i] = s[i][:j] + ('2' if s[i][j] != '2' else '1') + s[i][j + 1:]
	print('\n'.join(s))


x = int(input())
d = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'}
for a in range(x):
	arr = []
	for b in range(9):
		arr.append(list(input()))
	for b in range(3):
		for c in range(3):
			if arr[int(b * 3) + c][int(c * 3) + b] != '5':
				arr[int(b * 3) + c][int(c * 3) + b] = '5'
			else:
				arr[int(b * 3) + c][int(c * 3) + b] = '4'
	for each in arr:
		print(''.join(each))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	l = []
	for j in range(9):
		s = input()
		l.append(s)
	k = 0
	for j in range(0, 9, 3):
		l1 = list(l[j])
		if l1[k] != '1':
			l1[k] = '1'
		else:
			l1[k] = '2'
		l[j] = ''.join(l1)
		k += 1
	for j in range(1, 9, 3):
		l1 = list(l[j])
		if l1[k] != '1':
			l1[k] = '1'
		else:
			l1[k] = '2'
		l[j] = ''.join(l1)
		k += 1
	for j in range(2, 9, 3):
		l1 = list(l[j])
		if l1[k] != '1':
			l1[k] = '1'
		else:
			l1[k] = '2'
		l[j] = ''.join(l1)
		k += 1
	for j in l:
		print(j)


k = int(input())
for _ in range(k):
	sud = []
	for i in range(9):
		line = []
		for i in input():
			line.append(i)
		sud.append(line)
	places = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
	for (i, j) in places:
		if sud[i][j] == '9':
			sud[i][j] = '1'
		else:
			sud[i][j] = str(int(sud[i][j]) + 1)
	for i in sud:
		for j in i:
			print(j, end='')
		print()


t = int(input())
for k in range(t):
	M = []
	for l in range(9):
		line = list(input().strip())
		lix = [ord(c) - 48 for c in line]
		M.append(lix)
	M[0][0] = 1 + M[0][0] % 9
	M[1][3] = 1 + M[1][3] % 9
	M[2][6] = 1 + M[2][6] % 9
	M[3][1] = 1 + M[3][1] % 9
	M[4][4] = 1 + M[4][4] % 9
	M[5][7] = 1 + M[5][7] % 9
	M[6][2] = 1 + M[6][2] % 9
	M[7][5] = 1 + M[7][5] % 9
	M[8][8] = 1 + M[8][8] % 9
	for lix in M:
		for x in lix:
			print(x, end='')
		print()


t = int(input())
s = []

def pseudo_sudoku(s):
	s1 = [[y for y in x] for x in s]
	for i in range(9):
		row = column = 0
		if i % 3 == 0:
			first = i + 2
		else:
			first = i - 1
		if i // 3 == 0:
			second = i + 6
		else:
			second = i - 3
		for j in range(second // 3 * 3, second // 3 * 3 + 3):
			if 1 in s[j] and second % 3 * 3 <= s[j].index(1) <= second % 3 * 3 + 2:
				column = s[j].index(1)
		for k in range(first // 3 * 3, first // 3 * 3 + 3):
			if 1 in s[k] and first % 3 * 3 <= s[k].index(1) <= first % 3 * 3 + 2:
				row = k
		s1[row][column] = 1
	return s1
for i in range(t):
	s = []
	for j in range(9):
		s.append([int(x) for x in input()])
	s = pseudo_sudoku(s)
	for x in s:
		string = ''
		for m in x:
			string += str(m)
		print(string)


for _ in range(int(input())):
	b = []
	for i in range(9):
		a = list(input())
		for i in range(len(a)):
			if a[i] == '4':
				a[i] = 5
		b.append(a)
	for i in range(len(b)):
		p = str(b[i][0])
		for j in range(8):
			p += str(b[i][j + 1])
		print(p)


t = int(input())
for i in range(t):
	for j in range(9):
		row = input()
		for k in range(9):
			if row[k] == '2':
				row = row[:k] + '1' + row[k + 1:]
				break
		print(row)


import sys

def answer(x):
	if x == 9:
		return x - 1
	else:
		return (x + 1) % 10
t = int(sys.stdin.readline())
for _ in range(t):
	sudoku = [[int(char) for char in sys.stdin.readline().replace('\n', '')] for i in range(9)]
	sudoku[0][0] = answer(sudoku[0][0])
	sudoku[3][1] = answer(sudoku[3][1])
	sudoku[6][2] = answer(sudoku[6][2])
	sudoku[1][3] = answer(sudoku[1][3])
	sudoku[4][4] = answer(sudoku[4][4])
	sudoku[7][5] = answer(sudoku[7][5])
	sudoku[2][6] = answer(sudoku[2][6])
	sudoku[5][7] = answer(sudoku[5][7])
	sudoku[8][8] = answer(sudoku[8][8])
	for l in range(9):
		for c in range(9):
			print(sudoku[l][c], end='')
		print()


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

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect

def func(x):
	return s[x % (a * b)] + x // (a * b) * s[a * b - 1]
for _ in range(I()):
	s = [''] * 9
	s2 = [''] * 9
	for i in range(9):
		s[i] = S()
	for i in range(9):
		for j in range(9):
			if s[i][j] == '2':
				s2[i] += '1'
			else:
				s2[i] += s[i][j]
	for i in range(9):
		print(s2[i])


def solution():
	test = int(input())
	for i in range(0, test):
		s1 = int(input())
		s1 = list(map(int, str(s1)))
		s1[6] = s1[5]
		print(*s1, sep='')
		s1 = int(input())
		s1 = list(map(int, str(s1)))
		s1[1] = s1[0]
		print(*s1, sep='')
		s1 = int(input())
		s1 = list(map(int, str(s1)))
		s1[5] = s1[8]
		print(*s1, sep='')
		s1 = int(input())
		s1 = list(map(int, str(s1)))
		s1[8] = s1[5]
		print(*s1, sep='')
		s1 = int(input())
		s1 = list(map(int, str(s1)))
		s1[2] = s1[0]
		print(*s1, sep='')
		s1 = int(input())
		s1 = list(map(int, str(s1)))
		s1[4] = s1[7]
		print(*s1, sep='')
		s1 = int(input())
		s1 = list(map(int, str(s1)))
		s1[7] = s1[6]
		print(*s1, sep='')
		s1 = int(input())
		s1 = list(map(int, str(s1)))
		s1[0] = s1[1]
		print(*s1, sep='')
		s1 = int(input())
		s1 = list(map(int, str(s1)))
		s1[3] = s1[2]
		print(*s1, sep='')
solution()


tc = int(input())
SIZE = 9

def spoil(v):
	if v == '1':
		return '2'
	else:
		return '1'

def solve(grid):
	new_grid = [list(row) for row in grid]
	j = 0
	for i in range(SIZE):
		new_grid[i][j + i // 3] = spoil(grid[i][j + i // 3])
		j = (j + 3) % SIZE
	return new_grid
for _ in range(tc):
	grid = [input() for _ in range(SIZE)]
	for row in solve(grid):
		print(''.join(row))


t = int(input())
while t != 0:
	a = [input() for j in range(9)]
	b = []
	for i in range(9):
		c = []
		for j in range(9):
			if a[i][j] == '1':
				c.append(9)
			else:
				c.append(int(a[i][j]))
		b.append(c)
	for i in b:
		for j in i:
			print(j, end='')
		print()
	t = t - 1


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		for i in range(9):
			s = input()
			a = ''
			for i in range(9):
				if s[i] == '1':
					a += '2'
				else:
					a += s[i]
			print(a)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = int(input())
for _ in range(t):
	sudoku = [list(map(int, list(input()))) for _ in range(9)]
	sudoku[0][0] = sudoku[0][0] % 9 + 1
	sudoku[1][3] = sudoku[1][3] % 9 + 1
	sudoku[2][6] = sudoku[2][6] % 9 + 1
	sudoku[3][1] = sudoku[3][1] % 9 + 1
	sudoku[4][4] = sudoku[4][4] % 9 + 1
	sudoku[5][7] = sudoku[5][7] % 9 + 1
	sudoku[6][2] = sudoku[6][2] % 9 + 1
	sudoku[7][5] = sudoku[7][5] % 9 + 1
	sudoku[8][8] = sudoku[8][8] % 9 + 1
	for l in sudoku:
		print(''.join(map(str, l)))


t = int(input())
for _ in range(t):
	for i in range(9):
		s = ''
		s = input()
		l = []
		answer = ''
		for i in s:
			l.append(int(i))
		for i in range(len(l)):
			if l[i] == 2:
				l[i] = 1
		for i in l:
			answer += str(i)
		print(answer)


import string
T = int(input())
for t in range(T):
	A = [input().replace('1', '9') for i in range(9)]
	for i in range(9):
		print(A[i])


import math
import sys
from collections import defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]
INF = 10 ** 18
MOD = 1000000000 + 7
for _ in range(int(input())):
	B = []
	for i in range(9):
		A = input()
		B.append([*A])
	Ans = B.copy()
	for i in range(9):
		for j in range(9):
			if Ans[i][j] == '2':
				Ans[i][j] = '3'
	for i in Ans:
		for j in i:
			print(j, end='')
		print()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

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

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

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

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def solve():
	n = 9
	ar = [[int(i) for i in inp()] for _ in range(n)]
	for i in range(9):
		ar[i][ar[i].index(9)] = 1
	for i in ar:
		s = ''
		for j in i:
			s += str(j)
		print(s)
testcase(int(inp()))


t = int(input())
for i in range(t):
	l = []
	for k in range(9):
		l.append(list(input()))
	l[0][0] = int(l[0][0]) % 9 + 1
	l[3][1] = int(l[3][1]) % 9 + 1
	l[6][2] = int(l[6][2]) % 9 + 1
	l[1][3] = int(l[1][3]) % 9 + 1
	l[4][4] = int(l[4][4]) % 9 + 1
	l[7][5] = int(l[7][5]) % 9 + 1
	l[2][6] = int(l[2][6]) % 9 + 1
	l[5][7] = int(l[5][7]) % 9 + 1
	l[8][8] = int(l[8][8]) % 9 + 1
	for k in range(9):
		for j in range(9):
			print(l[k][j], end='')
		print()


t = int(input())
for i in range(t):
	s = []
	for k in range(9):
		x = []
		p = input()
		for j in range(9):
			x.append(int(p[j]))
		s.append(x)
	s[0][0] = s[1][0]
	s[1][3] = s[2][3]
	s[2][6] = s[3][6]
	s[3][1] = s[4][1]
	s[4][4] = s[5][4]
	s[5][7] = s[6][7]
	s[6][2] = s[7][2]
	s[7][5] = s[8][5]
	s[8][8] = s[0][8]
	for k in range(9):
		for j in range(9):
			print(s[k][j], end='')
		print('')


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def change(x):
	if x == 9:
		x = 1
	else:
		x += 1
	return x
t = int(input())
for _ in range(t):
	a = []
	for i in range(9):
		a.append(list(map(int, list(input()))))
	a[0][0] = change(a[0][0])
	a[3][1] = change(a[3][1])
	a[6][2] = change(a[6][2])
	a[1][3] = change(a[1][3])
	a[4][4] = change(a[4][4])
	a[7][5] = change(a[7][5])
	a[2][6] = change(a[2][6])
	a[5][7] = change(a[5][7])
	a[8][8] = change(a[8][8])
	for aa in a:
		print(''.join(map(str, aa)))


T = int(input())
for t in range(T):
	sudoku = []
	for d in range(9):
		sudoku.append([int(i) for i in input()])
	for i in range(3):
		for j in range(3):
			(l, c) = (i + 3 * j, j + 3 * i)
			sudoku[l][c] += 1
			if sudoku[l][c] == 10:
				sudoku[l][c] = 1
	for a in sudoku:
		print(''.join([str(g) for g in a]))


t = int(input())
for i in range(t):
	l = []
	for j in range(9):
		l.append([])
		l[j] = list(map(int, input()))
	for j in range(9):
		for k in range(9):
			if l[j][k] == 1:
				l[j][k] = 2
	for j in l:
		for k in j:
			print(k, end='')
		print()


t = int(input())
for _ in range(t):
	l = []
	for i in range(9):
		l.append(list(input()))
	k = 0
	m = 0
	for i in range(9):
		if l[i][m] == '9':
			l[i][m] = '1'
		else:
			l[i][m] = str(int(l[i][m]) + 1)
		m += 3
		if m >= 9:
			k += 1
			m = k
	for i in l:
		print(''.join(i))


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
t = read_int()
for i in range(t):
	g = []
	for i in range(9):
		row = read_line()
		g.append(row)
	ans = [[0 for j in range(9)] for i in range(9)]
	for i in range(9):
		for j in range(9):
			ans[i][j] = int(g[i][j])
	ans[0][0] = 9 - ans[0][0]
	ans[1][3] = 9 - ans[1][3]
	ans[2][6] = 9 - ans[2][6]
	ans[3][1] = 9 - ans[3][1]
	ans[4][4] = 9 - ans[4][4]
	ans[5][7] = 9 - ans[5][7]
	ans[6][2] = 9 - ans[6][2]
	ans[7][5] = 9 - ans[7][5]
	ans[8][8] = 9 - ans[8][8]
	for i in range(9):
		for j in range(9):
			if ans[i][j] == 0:
				print(ans[i][j] + 1, end='')
			else:
				print(ans[i][j], end='')
		print()


def inc(n):
	ar = [0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '1']
	return ar[int(n) + 1]
t = int(input())
for _ in range(t):
	sd = []
	for i in range(9):
		row = list(input())
		sd += [row]
	for i in range(0, 7, 3):
		sd[i][(i + 1) // 3] = inc(sd[i][(i + 1) // 3])
		sd[i + 1][(i + 1) // 3 + 3] = inc(sd[i + 1][(i + 1) // 3 + 3])
		sd[i + 2][(i + 1) // 3 + 6] = inc(sd[i + 2][(i + 1) // 3 + 6])
	for i in range(9):
		print(''.join(sd[i]))


from math import ceil, sqrt, floor, sqrt
import collections
from typing import List
from fractions import gcd
from collections import deque
from collections import defaultdict, Counter
t = int(input())
for _ in range(t):
	board = []
	for i in range(9):
		s = input()
		board.append(list(s))
	for (i, j) in [(8, 0), (5, 1), (2, 2), (7, 3), (4, 4), (1, 5), (6, 6), (3, 7), (0, 8)]:
		board[i][j] = '1' if board[i][j] != '1' else '2'
	for i in range(9):
		print(''.join((str(board[i][j]) for j in range(9))))


t = int(input())
for _ in range(t):
	for i in range(9):
		n = input()
		a = ''
		for i in n:
			if i == '1':
				a += '2'
			else:
				a += i
		print(a)


from sys import stdin

def solve(d):
	k = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for u in k:
		d[u[0]][u[1]] = (d[u[0]][u[1]] + 1) % 9 + 1
	for i in range(9):
		for j in range(9):
			print(d[i][j], end='')
		print()
	return

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		d = []
		for i in range(9):
			h = inp().strip()
			m = [int(h[i]) for i in range(9)]
			d.append(m)
		solve(d)
main()


t = int(input())
for i in range(t):
	l = [input().replace('1', '2') for j in range(9)]
	print('\n'.join(l))


t = int(input())
a = [0, 1, 2, 3, 4, 5, 6, 7, 8]
b = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for _ in range(t):
	Sudoku = []
	for i in range(9):
		line = input()
		Sudoku.append(list(line))
	for x in range(9):
		if Sudoku[a[x]][b[x]] != '2':
			Sudoku[a[x]][b[x]] = '2'
		else:
			Sudoku[a[x]][b[x]] = '1'
	for x in a:
		print(''.join(Sudoku[x]))


for _ in range(int(input())):
	mat = [[int(j) for j in input()] for i in range(9)]
	for i in range(9):
		for j in range(9):
			if mat[i][j] == 1:
				mat[i][j] += 1
			print(mat[i][j], end='')
		print()


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
alph = string.ascii_lowercase
for _ in range(ii()):
	d = []
	for _ in range(9):
		d.append([int(x) for x in input()])
	p = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		j = p[i]
		if d[i][j] < 9:
			d[i][j] += 1
		else:
			d[i][j] = 1
	for i in range(9):
		prr(d[i], '')


for _ in range(int(input())):
	a = []
	for i in range(9):
		a.append(list(input()))
	j = 0
	for i in range(3):
		if a[i][j] != '1':
			a[i][j] = '1'
		else:
			a[i][j] = '2'
		j += 3
	j = 1
	for i in range(3, 6):
		if a[i][j] != '1':
			a[i][j] = '1'
		else:
			a[i][j] = '2'
		j += 3
	j = 2
	for i in range(6, 9):
		if a[i][j] != '1':
			a[i][j] = '1'
		else:
			a[i][j] = '2'
		j += 3
	for i in a:
		for j in i:
			print(j, end='')
		print()


for i in range(int(input())):
	for i in range(9):
		s = map(lambda x: str(max(2, int(x))), input())
		print(''.join(s))


t = int(input())
for _ in range(t):
	a = []
	for _ in range(9):
		s = input()
		a.append(s)
	for i in range(9):
		st = a[i]
		print(st.replace('2', '1'))


t = int(input())
for i in range(t):
	new = [[0 for i in range(9)] for j in range(9)]
	sdk = [input() for i in range(9)]
	for j in range(9):
		for k in range(9):
			if sdk[j][k] == '1':
				new[j][k] = 2
			else:
				new[j][k] = int(sdk[j][k])
	for j in range(9):
		print(*new[j], sep='')


to_change = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
for _ in range(int(input())):
	grid = [[int(num) for num in input()] for _ in range(9)]
	for (r, c) in to_change:
		if grid[r][c] == 9:
			grid[r][c] = 1
		else:
			grid[r][c] += 1
	for row in grid:
		print(*row, sep='')


from collections import deque, defaultdict

def change(ar, x, y):
	ar[x][y] = ar[x][y] - 1 if ar[x][y] > 1 else ar[x][y] + 1
t = int(input())
for _ in range(t):
	ar = [list(map(int, input())) for _ in range(9)]
	change(ar, 0, 0)
	change(ar, 3, 1)
	change(ar, 6, 2)
	change(ar, 1, 3)
	change(ar, 4, 4)
	change(ar, 7, 5)
	change(ar, 2, 6)
	change(ar, 5, 7)
	change(ar, 8, 8)
	for x in ar:
		print(''.join(map(str, x)))


import sys, math, bisect
inf = float('inf')
mod = inf + 7

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

def gcd(a, b):
	return int(math.gcd(a, b))

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def freq(a, x):
	z = upperBound(a, x) - lowerBound(a, x)
	if z <= 0:
		return 0
	return z
for _ in range(int(input())):
	arr = []
	for _ in range(9):
		arr.append(list(input()))
	for i in range(9):
		for j in range(9):
			if arr[i][j] == '1':
				arr[i][j] = '2'
	for i in range(9):
		for j in range(9):
			print(arr[i][j], end='')
		print()


for _ in range(int(input())):
	sud = []
	for i in range(9):
		sud.append(list(map(int, list(input()))))
	for i in range(3):
		for g in range(3):
			if sud[i * 3 + g][g * 3 + i] == 1:
				sud[i * 3 + g][g * 3 + i] = 2
			else:
				sud[i * 3 + g][g * 3 + i] = 1
	for i in range(9):
		print(''.join(list(map(str, sud[i]))))


t = int(input())
while t:
	for _ in range(9):
		listt = list(input())
		for i in range(len(listt)):
			if listt[i] == '1':
				listt[i] = '2'
				break
		print(''.join(listt))
	t -= 1


t = int(input())
for i in range(t):
	rows = []
	for i in range(9):
		row = list(map(int, input()))
		(big_r, small_r) = (i // 3 + 1, i % 3)
		idx = big_r + small_r * 3 - 1
		val = row[idx]
		row[idx] = int(val) % 9 + 1
		rows.append(row)
	for j in range(9):
		print(''.join((str(i) for i in rows[j])))


test = int(input())
sol = []
while test:
	test -= 1
	a = []
	for i in range(9):
		c = []
		d = input()
		for i in d:
			c.append(int(i))
		a.append(c.copy())
	i = 0
	j = 0
	pas = 0
	while i < 9 and j < 9:
		if a[i][j] == 1:
			a[i][j] = 2
		else:
			a[i][j] = 1
		i += 1
		j += 3
		if j >= 9:
			if pas == 0:
				j = 1
			else:
				j = 2
			pas += 1
	c = []
	for i in a:
		c.append(i.copy())
	sol.append(c)
for i in sol:
	for j in i:
		print(*j, sep='')


t = int(input())
for _ in range(t):
	s = []
	for _ in range(9):
		s.append(input())
	for i in range(9):
		s[i] = s[i][:3 * (i % 3) + i // 3] + '2' + s[i][3 * (i % 3) + i // 3 + 1:] if s[i][3 * (i % 3) + i // 3] == '1' else s[i][:3 * (i % 3) + i // 3] + '1' + s[i][3 * (i % 3) + i // 3 + 1:]
	for row in s:
		print(row)


t = int(input())
for case in range(t):
	for i in range(9):
		row = input()
		print(row.replace('2', '1'))


t = int(input())
for test in range(t):
	x = []
	for i in range(9):
		temp = input()
		temp = list(temp)
		x.append(temp)
	temp = [0, 4, 8, 1, 5, 6, 2, 3, 7]
	for i in range(len(x)):
		if x[i][temp[i]] != '5':
			x[i][temp[i]] = str(10 - int(x[i][temp[i]]))
		else:
			x[i][temp[i]] = '1'
	for i in range(len(x)):
		s = ''.join(x[i])
		print(s)


t = int(input())
for k in range(t):
	sudoku = [[0] * 9 for i in range(9)]
	for j in range(9):
		ligne = input()
		for l in range(9):
			sudoku[j][l] = int(ligne[l])
	if sudoku[0][0] == 9:
		sudoku[0][0] -= 1
	else:
		sudoku[0][0] += 1
	if sudoku[1][4] == 9:
		sudoku[1][4] -= 1
	else:
		sudoku[1][4] += 1
	if sudoku[2][8] == 9:
		sudoku[2][8] -= 1
	else:
		sudoku[2][8] += 1
	if sudoku[3][3] == 9:
		sudoku[3][3] -= 1
	else:
		sudoku[3][3] += 1
	if sudoku[4][7] == 9:
		sudoku[4][7] -= 1
	else:
		sudoku[4][7] += 1
	if sudoku[5][1] == 9:
		sudoku[5][1] -= 1
	else:
		sudoku[5][1] += 1
	if sudoku[6][2] == 9:
		sudoku[6][2] -= 1
	else:
		sudoku[6][2] += 1
	if sudoku[7][5] == 9:
		sudoku[7][5] -= 1
	else:
		sudoku[7][5] += 1
	if sudoku[8][6] == 9:
		sudoku[8][6] -= 1
	else:
		sudoku[8][6] += 1
	for j in range(9):
		for z in range(9):
			print(sudoku[j][z], end='')
		print()


for _ in range(int(input())):
	board = [list(map(int, list(input()))) for _ in range(9)]
	visited = [[0] * 9 for _ in range(9)]
	col = 0
	for row in range(9):
		col %= 8
		if row == 8 and (not col):
			col = 8
		board[row][col] = board[row][col] + 1 if board[row][col] != 9 else board[row][col] - 1
		for i in range(9):
			visited[i][col] = 1
		col += 3
	for a in board:
		print(''.join(map(str, a)))


from sys import stdin

def go(x):
	s = list(stdin.readline())
	s[x] = str(int(s[x]) % 9 + 1)
	return ''.join(s)
t = int(stdin.readline())
for _ in range(t):
	ans = ''
	ans += go(2)
	ans += go(5)
	ans += go(8)
	ans += go(1)
	ans += go(4)
	ans += go(7)
	ans += go(0)
	ans += go(3)
	ans += go(6)
	print(ans)


def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def solve():
	sudoku = []
	for i in range(9):
		sudoku.append(list(input().strip()))
	for (row, col) in zip(range(9), [0, 3, 6, 1, 4, 7, 2, 5, 8]):
		if col % 3 == 0:
			sudoku[row][col] = sudoku[row][col + 1]
		else:
			sudoku[row][col] = sudoku[row][col - 1]
	for row in sudoku:
		print(''.join(row))

def is_anti(sudoku):
	for row in sudoku:
		if set(row) == 9:
			return False
	for row in zip(*sudoku):
		if set(row) == 9:
			return False
	for i in range(0, 9, 3):
		for j in range(0, 9, 3):
			nums = []
			for x in range(i, i + 3):
				for y in range(j, j + 3):
					nums.append(sudoku[x][y])
			if len(set(nums)) == 9:
				return False
	return True
T = read_int()
for _ in range(T):
	solve()


for _ in range(int(input())):
	arr = []
	for i in range(9):
		a = list(input())
		arr.append(a)
	arr[0][1] = arr[0][0]
	arr[1][4] = arr[1][3]
	arr[2][7] = arr[2][6]
	arr[3][0] = arr[3][2]
	arr[4][3] = arr[4][5]
	arr[5][6] = arr[5][8]
	arr[6][2] = arr[6][1]
	arr[7][5] = arr[7][4]
	arr[8][8] = arr[8][7]
	for i in range(9):
		for j in range(9):
			print(arr[i][j], end='')
		print()


t = int(input())
for _ in range(t):
	a = []
	for i in range(9):
		s = [int(x) for x in input()]
		a.append(s)
	c = 0
	i = 0
	j = 0
	initj = 0
	while c != 9:
		if (i + 1) % 3 != 0:
			a[i][j] = a[i + 1][j]
			i += 1
			j += 3
		else:
			a[i][j] = a[i - 1][j]
			initj += 1
			j = initj
			i += 1
		c += 1
	for i in range(9):
		rs = ''.join((str(x) for x in a[i]))
		print(rs)


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	l1 = stdin.readline()
	l1 = [int(x) for x in list(l1[:-1])]
	if l1[0] != 9:
		l1[0] += 1
	else:
		l1[0] = 1
	l11 = ''
	for x in l1:
		l11 += str(x)
	l2 = stdin.readline()
	l2 = [int(x) for x in list(l2[:-1])]
	if l2[4] != 9:
		l2[4] += 1
	else:
		l2[4] = 1
	l21 = ''
	for x in l2:
		l21 += str(x)
	l3 = stdin.readline()
	l3 = [int(x) for x in list(l3[:-1])]
	if l3[8] != 9:
		l3[8] += 1
	else:
		l3[8] = 1
	l31 = ''
	for x in l3:
		l31 += str(x)
	l4 = stdin.readline()
	l4 = [int(x) for x in list(l4[:-1])]
	if l4[6] != 9:
		l4[6] += 1
	else:
		l4[6] = 1
	l41 = ''
	for x in l4:
		l41 += str(x)
	l5 = stdin.readline()
	l5 = [int(x) for x in list(l5[:-1])]
	if l5[1] != 9:
		l5[1] += 1
	else:
		l5[1] = 1
	l51 = ''
	for x in l5:
		l51 += str(x)
	l6 = stdin.readline()
	l6 = [int(x) for x in list(l6[:-1])]
	if l6[5] != 9:
		l6[5] += 1
	else:
		l6[5] = 1
	l61 = ''
	for x in l6:
		l61 += str(x)
	l7 = stdin.readline()
	l7 = [int(x) for x in list(l7[:-1])]
	if l7[3] != 9:
		l7[3] += 1
	else:
		l7[3] = 1
	l71 = ''
	for x in l7:
		l71 += str(x)
	l8 = stdin.readline()
	l8 = [int(x) for x in list(l8[:-1])]
	if l8[7] != 9:
		l8[7] += 1
	else:
		l8[7] = 1
	l81 = ''
	for x in l8:
		l81 += str(x)
	l9 = stdin.readline()
	l9 = [int(x) for x in list(l9[:-1])]
	if l9[2] != 9:
		l9[2] += 1
	else:
		l9[2] = 1
	l91 = ''
	for x in l9:
		l91 += str(x)
	stdout.write(l11 + '\n')
	stdout.write(l21 + '\n')
	stdout.write(l31 + '\n')
	stdout.write(l41 + '\n')
	stdout.write(l51 + '\n')
	stdout.write(l61 + '\n')
	stdout.write(l71 + '\n')
	stdout.write(l81 + '\n')
	stdout.write(l91 + '\n')


t = int(input())
for _ in range(t):
	for i in [0, 3, 6, 1, 4, 7, 2, 5, 8]:
		l = list(input())
		if l[i] == '9':
			l[i] = '1'
		else:
			l[i] = str(int(l[i]) + 1)
		print(''.join(l))


import sys
input = sys.stdin.buffer.readline
tests = int(input())
for ii in range(tests):
	for i in range(9):
		s = input()
		cur = 3 * (i % 3) + i // 3
		x = s[cur] - 48
		if x != 1:
			x -= 1
		else:
			x += 1
		for j in range(9):
			if j == cur:
				print(x, end='')
			else:
				print(s[j] - 48, end='')
		print()


t = int(input())
for _ in range(t):
	for i in range(3):
		for j in range(3):
			l = [*input()]
			l[i + j * 3] = chr(ord('0') + int(l[i + j * 3]) % 9 + 1)
			print(''.join(l))


T = int(input())
d = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
for t in range(T):
	a = []
	for i in range(9):
		a.append(input())
	for i in d:
		x = i[0]
		y = i[1]
		if a[y][x] == '1':
			print(a[y][:x] + '9' + a[y][x + 1:])
		else:
			print(a[y][:x] + '1' + a[y][x + 1:])


t = int(input())
for _ in range(t):
	sudoku = []
	for i in range(9):
		s = input().replace('1', '2')
		sudoku.append(s)
	for i in sudoku:
		print(i)


n = int(input())
for _ in range(n):
	for i in range(9):
		s = input()
		s = s.replace('1', '2')
		print(s)


from typing import List
from sys import stdin, stdout

def read():
	a = []
	for i in range(9):
		a.append(stdin.readline())
	return a

def solve(a: List[str]):
	for i in range(9):
		a[i] = a[i].replace('2', '1')
	return a
for t in range(int(input())):
	result = solve(read())
	stdout.writelines(result)


def main():
	from collections import Counter
	import sys
	input = sys.stdin.buffer.readline

	def GCD(x, y):
		while y:
			(x, y) = (y, x % y)
		return x

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

	def merge(a, start, mid, end, d):
		p = start
		q = mid + 1
		arr = [0] * (end - start + 1)
		k = 0
		coun = 0
		for i in range(start, end + 1):
			if p > mid:
				arr[k] = a[q]
				q += 1
				k += 1
			elif q > end:
				arr[k] = a[p]
				d[a[p]] += coun
				k += 1
				p += 1
			elif a[p] < a[q]:
				arr[k] = a[p]
				d[a[p]] += coun
				k += 1
				p += 1
			else:
				arr[k] = a[q]
				k += 1
				q += 1
				coun += 1
		for i in range(k):
			a[start] = arr[i]
			start += 1

	def mergesort(a, start, end, d):
		if start < end:
			mid = (start + end) // 2
			mergesort(a, start, mid, d)
			mergesort(a, mid + 1, end, d)
			merge(a, start, mid, end, d)

	def inversion(l):
		d = {}
		for i in l:
			d[i] = 0
		mergesort(l, 0, len(l) - 1, d)
		return d

	def binary_search_lower(A, low, high, k):
		if high - low != 1:
			mid = (low + high) // 2
			x = A[mid]
			if x >= k:
				return binary_search_lower(A, low, mid, k)
			else:
				return binary_search_lower(A, mid, high, k)
		if A[low] >= k:
			return low
		else:
			return high

	def binary_expo(x, n):
		if n == 0:
			return 1
		elif n % 2 == 0:
			return binary_expo(x * x, n // 2)
		else:
			return x * binary_expo(x * x, (n - 1) // 2)

	def modu_expo(x, n, m):
		if n == 0:
			return 1
		elif n % 2 == 0:
			return modu_expo(x * x % m, n // 2, m)
		else:
			return x * modu_expo(x * x % m, (n - 1) // 2, m) % m

	def eEuclid(c, m):
		if m == 0:
			global d
			global x
			global y
			d = c
			x = 1
			y = 0
		else:
			eEuclid(m, c % m)
			temp = x
			x = y
			y = temp - c // m * y

	def mod_Inv(c, m):
		eEuclid(c, m)
		return (x % m + m) % m

	def ncr(n, r, p):
		num = den = 1
		for i in range(r):
			num = num * (n - i) % p
			den = den * (i + 1) % p
		return num * pow(den, p - 2, p) % p

	def change(x):
		if x == '9':
			return '1'
		else:
			return '9'
	for _ in range(int(input())):
		l = []
		for i in range(9):
			l.append(list(str(input())))
		for i in l:
			i.pop()
			i.pop()
			i.pop()
			i.pop(0)
			i.pop(0)
		x = l[0][0]
		l[0][0] = change(x)
		x = l[1][4]
		l[1][4] = change(x)
		x = l[2][8]
		l[2][8] = change(x)
		x = l[3][2]
		l[3][2] = change(x)
		x = l[4][3]
		l[4][3] = change(x)
		x = l[5][7]
		l[5][7] = change(x)
		x = l[6][1]
		l[6][1] = change(x)
		x = l[7][5]
		l[7][5] = change(x)
		x = l[8][6]
		l[8][6] = change(x)
		for i in range(9):
			for j in range(9):
				print(l[i][j], end='')
			print()
main()


import math
t = int(input())
for _ in range(t):
	sudoku = []
	for i in range(9):
		arr = list(map(int, input().strip()))
		sudoku.append(arr)
	for i in range(9):
		for j in range(9):
			if sudoku[i][j] == 1:
				sudoku[i][j] = 2
	for i in range(9):
		print(''.join(map(str, sudoku[i])))


def RA():
	l = input().split()
	return [int(s) for s in l]

def solve():
	for i in range(9):
		l = input()
		n = ''
		for c in l:
			if c == '1':
				n += '2'
			else:
				n += c
		print(n)
t = int(input())
for i in range(t):
	solve()


def answer(m):
	for i in range(9):
		l = list(m[i])
		indx = l.index('2')
		l[indx] = '1'
		m[i] = ''.join(l)
		print(m[i])
	return

def main():
	t = int(input())
	m = [0] * t
	for j in range(t):
		m[j] = []
		for i in range(9):
			m[j].append(input())
	for j in range(t):
		answer(m[j])
main()


t = int(input())
while t > 0:
	ls = []
	e = []
	a = [0, 0, 0, 0, 0, 0, 0, 0, 0]
	for _ in range(3):
		l = []
		x = input()
		for i in x:
			l.append(int(i))
		for j in range(_ % 3 * 3, _ % 3 * 3 + 3):
			if l[j] != 1 and a[j] < 1:
				l[j] = 1
				a[j] += 1
				break
		ls.append(l)
	for _ in range(3, 9):
		l = []
		x = input()
		for i in x:
			l.append(int(i))
		ex = []
		for j in range(_ % 3 * 3, _ % 3 * 3 + 3):
			if l[j] != 1 and a[j] < 1:
				ex.append(j)
		e.append(ex)
		ls.append(l)
	if len(e[0]) == 1:
		ls[3][e[0][0]] = 1
		a[e[0][0]] += 1
		for i in e[3]:
			if a[i] < 1:
				ls[6][i] = 1
				a[i] += 1
	else:
		ls[6][e[3][0]] = 1
		a[e[3][0]] += 1
		for i in e[0]:
			if a[i] < 1:
				ls[3][i] = 1
				a[i] += 1
	if len(e[1]) == 1:
		ls[4][e[1][0]] = 1
		a[e[1][0]] += 1
		for i in e[4]:
			if a[i] < 1:
				ls[7][i] = 1
				a[i] += 1
	else:
		ls[7][e[4][0]] = 1
		a[e[4][0]] += 1
		for i in e[1]:
			if a[i] < 1:
				ls[4][i] = 1
				a[i] += 1
	if len(e[2]) == 1:
		ls[5][e[2][0]] = 1
		a[e[2][0]] += 1
		for i in e[5]:
			if a[i] < 1:
				ls[8][i] = 1
				a[i] += 1
	else:
		ls[8][e[5][0]] = 1
		a[e[5][0]] += 1
		for i in e[2]:
			if a[i] < 1:
				ls[5][i] = 1
				a[i] += 1
	for i in range(9):
		for j in range(9):
			print(ls[i][j], end='')
		print()
	t -= 1


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
d = defaultdict(int)
x = 'abcdefghijklmnopqrstuvwxyz'
t = I()
for _ in range(t):
	w = []
	for i in range(9):
		s = input().strip()
		s1 = [i for i in s]
		w.append(s1)
	c = 0
	for i in range(0, 9, 3):
		k = i
		for j in range(c, 9, 3):
			w[k][j] = str(int(w[k][j]) - 1)
			if w[k][j] == '0':
				w[k][j] = '9'
			k += 1
		c += 1
	for i in range(9):
		for j in w[i]:
			print(j, end='')
		print()


from sys import stdin
input = stdin.readline
for t in range(int(input())):
	a = []
	for i in range(9):
		a.append(list(input().strip()))
	b = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		if a[i][b[i]] != '1':
			a[i][b[i]] = '1'
		else:
			a[i][b[i]] = '2'
	for i in a:
		print(''.join(i))


def solve():
	for _ in range(9):
		print(input().replace('9', '6'))
t = int(input())
for _ in range(t):
	solve()


import random
n = int(input())
for i in range(n):
	lst = []
	for j in range(9):
		l = input()
		l1 = []
		for ch in l:
			l1.append(ch)
		lst.append(l1)
	c = str(random.randint(1, 9))
	while lst[0][0] == c:
		c = str(random.randint(1, 9))
	lst[0][0] = c
	while lst[3][1] == c:
		c = str(random.randint(1, 9))
	lst[3][1] = c
	while lst[6][2] == c:
		c = str(random.randint(1, 9))
	lst[6][2] = c
	while lst[1][4] == c:
		c = str(random.randint(1, 9))
	lst[1][4] = c
	while lst[2][8] == c:
		c = str(random.randint(1, 9))
	lst[2][8] = c
	while lst[4][3] == c:
		c = str(random.randint(1, 9))
	lst[4][3] = c
	while lst[5][7] == c:
		c = str(random.randint(1, 9))
	lst[5][7] = c
	while lst[7][5] == c:
		c = str(random.randint(1, 9))
	lst[7][5] = c
	while lst[8][6] == c:
		c = str(random.randint(1, 9))
	lst[8][6] = c
	for j in range(9):
		print(''.join(lst[j]))


def ans(sudoku):
	changes = 9
	indices = [[0, 6], [1, 1], [2, 5], [3, 8], [4, 2], [5, 4], [6, 7], [7, 0], [8, 3]]
	k = 0
	while changes > 0:
		row = sudoku[indices[k][0]]
		column = [sudoku[i][indices[k][1]] for i in range(9)]
		a = list(set(column))
		b = list(set(row))
		for i in range(len(a)):
			if a[i] == sudoku[indices[k][0]][indices[k][1]]:
				del a[i]
				break
		for i in range(len(b)):
			if b[i] == sudoku[indices[k][0]][indices[k][1]]:
				del b[i]
				break
		for i in range(len(a)):
			if a[i] in b:
				sudoku[indices[k][0]][indices[k][1]] = a[i]
				break
		k += 1
		changes -= 1
	return sudoku
n = int(input())
for i in range(n):
	sudoku = []
	for j in range(9):
		m = input()
		a = []
		for k in range(9):
			a.append(m[k])
		sudoku.append(a)
	s = ans(sudoku)
	for i in s:
		w = ''.join(i)
		print(w)


import math
t = int(input())
for _ in range(t):
	S = []
	for i in range(9):
		l = list(input())
		l = list(map(int, l))
		S.append(l)
	places = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
	num = [i for i in range(1, 10)]
	for j in places:
		(a, b) = (j[0], j[1])
		S[a][b] = num[S[a][b] - 2]
	for i in range(9):
		print(*S[i], sep='')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	a = [list(input()[:-1]) for _ in range(9)]
	for i in range(9):
		for j in range(9):
			if a[i][j] == '9':
				a[i][j] = '8'
	for ai in a:
		print(''.join(ai))


for _ in range(int(input())):
	s = [list(input()) for i in range(9)]
	for (i, j) in [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]:
		if s[i][j] == '1':
			s[i][j] = '2'
		else:
			s[i][j] = '1'
	for i in range(9):
		print(''.join(s[i]))


def func(i, j):
	global a
	if a[i][j] == 9:
		a[i][j] = 1
	else:
		a[i][j] += 1
for b in range(int(input())):
	a = []
	for i in range(9):
		a.append(list(map(int, str(input()))))
	func(0, 0)
	func(1, 3)
	func(2, 6)
	func(3, 1)
	func(4, 4)
	func(5, 7)
	func(6, 2)
	func(7, 5)
	func(8, 8)
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print('')


cases = int(input())
for p in range(0, cases):
	ls = [[]]
	for l in range(9):
		inpu = input()
		ls.append([])
		for i in range(9):
			ls[l].append(inpu[i])
	for i in range(3):
		for x in range(3):
			if int(ls[i + 3 * x][x + i * 3]) != 9:
				ls[i + 3 * x][x + i * 3] = 9
			elif int(ls[i + 3 * x][x + i * 3]) == 9:
				ls[i + 3 * x][x + i * 3] = 8
	for l in range(9):
		print('')
		for i in range(9):
			print(ls[l][i], end='')


t = int(input())
for _ in range(t):
	matrix = [[int(x) for x in input()] for i in range(9)]
	for (i, row) in enumerate(matrix):
		if i == 8:
			continue
		block = i % 3
		temp = row[8]
		row[block * 3 + i // 3] = temp
	temp = matrix[8][0]
	matrix[8][8] = temp
	for row in matrix:
		for item in row:
			print(item, end='')
		print()


h = int(input())
for i in range(h):
	l = []
	for i in range(9):
		l.append(input())
	t = []
	for i in range(9):
		t.append([])
		for j in range(9):
			t[i].append(int(l[i][j]))
	i = 0
	x = 0
	while i < 9:
		if t[i][x] < 9:
			t[i][x] = t[i][x] + 1
		else:
			t[i][x] -= 1
		x = x + 3
		if x > 8:
			x = x - 8
		i += 1
	for i in range(9):
		for j in range(9):
			t[i][j] = str(t[i][j])
		l[i] = ''.join(t[i])
		print(l[i])


for i in range(int(input())):
	arr = []
	for j in range(9):
		p = input()
		p = p.replace('1', '2')
		print(p)


from sys import stdout, stdin, setrecursionlimit
from math import log2, floor
mod = 1000000007
cin = stdin.readline
cout = stdout.write
import string
aplha = string.ascii_lowercase

def find(x):
	for i in range(1, 10):
		if i != x:
			return i

def main():
	a = [0] * 9
	for i in range(0, 9):
		x = int(cin())
		y = []
		while x > 0:
			y.append(x % 10)
			x //= 10
		y.reverse()
		a[i] = y
	aa = []
	aa.append([0, 0])
	aa.append([1, 3])
	aa.append([2, 6])
	aa.append([3, 1])
	aa.append([4, 4])
	aa.append([5, 7])
	aa.append([6, 2])
	aa.append([7, 5])
	aa.append([8, 8])
	for j in aa:
		a[j[0]][j[1]] = find(a[j[0]][j[1]])
	for i in range(0, 9):
		for j in a[i]:
			cout(f'{j}')
		cout('\n')
t = 1
t = int(input())
while t > 0:
	main()
	t = t - 1


for ekbaar in range(1):
	for tin in range(int(input())):
		a = []
		for _ in range(9):
			s = list(str(input()))
			s = [int(s[_]) for _ in range(len(s))]
			a.append(s)
		b = [[0, 0], [3, 1], [6, 2], [1, 3], [4, 4], [7, 5], [2, 6], [5, 7], [8, 8]]
		for _ in range(len(b)):
			if a[b[_][0]][b[_][1]] == 9:
				a[b[_][0]][b[_][1]] = 1
			else:
				a[b[_][0]][b[_][1]] = a[b[_][0]][b[_][1]] + 1
		for _ in range(len(a)):
			for i in range(len(a[_]) - 1):
				print(a[_][i], end='')
			print(a[_][-1])


t = int(input())
for _ in range(t):
	for _ in range(9):
		s = list(input())
		for i in range(9):
			if s[i] == '2':
				s[i] = '1'
				break
		print(''.join(s))


t = int(input())
for _ in range(t):
	b = []
	for _ in range(9):
		b.append(input())
	for line in b:
		print(line.replace('1', '9'))


t = int(input())
for i in range(t):
	str = list(input())
	str[0] = str[1]
	print(''.join(str))
	str = list(input())
	str[3] = str[4]
	print(''.join(str))
	str = list(input())
	str[6] = str[7]
	print(''.join(str))
	str = list(input())
	str[1] = str[2]
	print(''.join(str))
	str = list(input())
	str[4] = str[5]
	print(''.join(str))
	str = list(input())
	str[7] = str[8]
	print(''.join(str))
	str = list(input())
	str[2] = str[3]
	print(''.join(str))
	str = list(input())
	str[5] = str[6]
	print(''.join(str))
	str = list(input())
	str[8] = str[0]
	print(''.join(str))


import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
a = int(input())
for i in range(a):
	ans = []
	for i in range(9):
		z = input()
		kap = []
		for i in range(len(z)):
			kap.append(int(z[i]))
		ans.append(kap)
	if ans[0][0] == 1:
		ans[0][0] = 2
	else:
		ans[0][0] = 1
	if ans[1][3] == 1:
		ans[1][3] = 2
	else:
		ans[1][3] = 1
	if ans[2][6] == 1:
		ans[2][6] = 2
	else:
		ans[2][6] = 1
	if ans[3][1] == 1:
		ans[3][1] = 2
	else:
		ans[3][1] = 1
	if ans[4][4] == 1:
		ans[4][4] = 2
	else:
		ans[4][4] = 1
	if ans[5][7] == 1:
		ans[5][7] = 2
	else:
		ans[5][7] = 1
	if ans[6][2] == 1:
		ans[6][2] = 2
	else:
		ans[6][2] = 1
	if ans[7][5] == 1:
		ans[7][5] = 2
	else:
		ans[7][5] = 1
	if ans[8][8] == 1:
		ans[8][8] = 2
	else:
		ans[8][8] = 1
	for i in range(len(ans)):
		x = ans[i]
		print(''.join(map(str, x)))


n = int(input())
for j in range(n):
	lis = []
	for i in range(9):
		s = input()
		f = []
		for k in s:
			f.append(k)
		lis.append(f)
	k = 0
	o = 0
	for i in range(8):
		lis[i][k] = lis[i + 1][k]
		if k + 3 >= 9:
			o += 1
			k = o
		else:
			k = (k + 3) % 9
	lis[8][8] = lis[7][8]
	for i in range(9):
		s = ''.join(lis[i])
		print(s)


from heapq import *
from collections import *
import os
import sys
from io import BytesIO, IOBase
import math
ins = lambda : [int(x) for x in input()]
inp = lambda : int(input())
inps = lambda : [int(x) for x in input().split()]

def main():
	t = inp()
	for i in range(t):
		sud = []
		for i in range(9):
			sud.append(ins())
		for rows in range(3):
			for j in range(3):
				fr = rows * 3 + j
				fc = rows + j * 3
				sud[fr][fc] += 1
				if sud[fr][fc] == 10:
					sud[fr][fc] = 1
		for i in range(9):
			for j in range(9):
				print(sud[i][j], end='')
			print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import Counter
for _ in range(int(input())):
	l = []
	for i in range(9):
		l.append(input())
	p = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for x in range(9):
		i = p[x][0]
		j = p[x][1]
		if l[i][j] != '9':
			l[i] = l[i][:j] + '9' + l[i][j + 1:]
		else:
			l[i] = l[i][:j] + '1' + l[i][j + 1:]
		print(l[i])


import math
test = int(input())

def most_frequent(List):
	un = set(List)
	num = max(un, key=List.count)
	count = 0
	for ele in List:
		if ele == num:
			count += 1
	return (num, count, len(un))
while test:
	ans = []
	ans.append([0, 0, 0, 0, 0, 0, 0, 0, 0])
	for i in range(1, 10):
		string = input()
		arr = [int(x) for x in string]
		if i % 10 == 1:
			arr[0] = arr[1]
		elif i % 10 == 2:
			arr[3] = arr[4]
		elif i % 10 == 3:
			arr[6] = arr[7]
		elif i % 10 == 4:
			arr[1] = arr[0]
		elif i % 10 == 5:
			arr[4] = arr[3]
		elif i % 10 == 6:
			arr[7] = arr[6]
		elif i % 10 == 7:
			arr[2] = arr[1]
		elif i % 10 == 8:
			arr[5] = arr[4]
		elif i % 10 == 9:
			arr[8] = arr[7]
		ans.append(arr)
	for i in range(1, 10):
		print(''.join((str(x) for x in ans[i])))
	test -= 1


T = int(input())
for cs in range(T):
	s = [input() for i in range(9)]
	for r in s:
		for c in r:
			if c == '1':
				print('2', end='')
			else:
				print(c, end='')
		print()


from collections import Counter

def main():
	for _ in range(int(input())):
		l = [list(map(int, list(input()))) for i in range(9)]
		l1 = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
		for i in l1:
			j = i[1]
			if l[i[0]][j] == 5:
				l[i[0]][j] = 4
			else:
				l[i[0]][j] = 10 - l[i[0]][j]
		for i in range(9):
			print(''.join(list(map(str, l[i]))))
main()


import sys
input = sys.stdin.readline
t = int(input())

def printmat(mat):
	for i in mat:
		for j in i:
			print(j, end='')
		print()
for r in range(t):
	mat = []
	for i in range(9):
		s = input().strip('\n')
		temp = []
		for j in s:
			temp.append(j)
		mat.append(temp)
	d = {}
	mat[1][3] = mat[1][0]
	d[mat[1][3]] = 1
	mat[2][6] = mat[2][0]
	d[mat[2][6]] = 1
	mat[3][2] = mat[3][0]
	d[mat[3][4]] = 1
	mat[4][4] = mat[4][0]
	d[mat[4][4]] = 1
	mat[5][7] = mat[5][0]
	d[mat[5][7]] = 1
	mat[7][5] = mat[7][0]
	d[mat[7][5]] = 1
	mat[8][8] = mat[8][0]
	d[mat[8][8]] = 1
	mat[6][0] = mat[0][0]
	d[mat[6][0]] = 1
	mat[0][1] = mat[0][0]
	printmat(mat)


for _ in range(int(input())):
	s = list()
	for i in range(9):
		s.append(input())
	s[0] = s[0][1] + s[0][1:]
	s[1] = s[1][:3] + s[1][4] + s[1][4:]
	s[2] = s[2][:6] + s[2][7] + s[2][7:]
	s[3] = s[3][0] + s[3][2] + s[3][2:]
	s[4] = s[4][:4] + s[4][5] + s[4][5:]
	s[5] = s[5][:7] + s[5][8] + s[5][8]
	s[6] = s[6][:2] + s[6][0] + s[6][3:]
	s[7] = s[7][:5] + s[7][3] + s[7][6:]
	s[8] = s[8][:8] + s[8][6]
	print(*s, sep='\n')


t = int(input())
for _ in range(t):
	m = []
	for i in range(9):
		s = input()
		n = ''
		for j in range(9):
			if s[j] == '1':
				n += '2'
			else:
				n += s[j]
		m.append(n)
	for i in m:
		print(i)


for tc in range(int(input())):
	mat = []
	for i in range(9):
		mat.append(list(map(int, list(input()))))
	i = 0
	while i < 9:
		q = i // 3
		for j in range(q, 9, 3):
			if mat[i][j] == 9:
				mat[i][j] = 1
			else:
				mat[i][j] += 1
			i += 1
	for i in mat:
		print(''.join(map(str, i)))


t = int(input())
for _ in range(t):
	mat = []
	for x in range(9):
		y = x % 3 * 3 + x // 3
		vec = list(input())
		for z in vec:
			if vec[y] != z:
				vec[y] = z
				break
		mat.append(''.join(vec))
	print('\n'.join(mat))


import math

def anti_sudoku(sudoku):
	for i in range(0, 9):
		for j in range(0, 9):
			if sudoku[i][j] == 1:
				sudoku[i][j] = 2
	for i in range(0, 9):
		print(''.join(map(str, sudoku[i])))
t = int(input())
for i in range(0, t):
	sudoku = []
	for j in range(0, 9):
		sudoku.append([int(char) for char in input()])
	anti_sudoku(sudoku)


from sys import stdin, stdout
t = int(stdin.readline())
while t > 0:
	for i in range(9):
		a = input().replace('3', '1')
		stdout.write(str(a))
		stdout.write('\n')
	t -= 1


cases = int(input())
pos = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
ans = []
while cases:
	cases -= 1
	sudoku = []
	for i in range(9):
		sudoku.append([int(x) for x in input()])
	for p in pos:
		sudoku[p[0]][p[1]] = sudoku[p[0]][p[1]] % 9 + 1
	ans.append(sudoku)
for a in ans:
	for r in a:
		print(''.join([str(x) for x in r]))


def main():
	for _ in range(int(input())):
		mat = list()
		for i in range(9):
			l = input()
			temp = list()
			for j in range(9):
				temp.append(int(l[j]))
			mat.append(temp)
		if mat[0][0] != 5:
			mat[0][0] = 10 - mat[0][0]
		else:
			mat[0][0] = 1
		if mat[1][3] != 5:
			mat[1][3] = 10 - mat[1][3]
		else:
			mat[1][3] = 1
		if mat[2][6] != 5:
			mat[2][6] = 10 - mat[2][6]
		else:
			mat[2][6] = 2
		if mat[3][1] != 5:
			mat[3][1] = 10 - mat[3][1]
		else:
			mat[3][1] = 3
		if mat[4][4] != 5:
			mat[4][4] = 10 - mat[4][4]
		else:
			mat[4][4] = 2
		if mat[5][7] != 5:
			mat[5][7] = 10 - mat[5][7]
		else:
			mat[5][7] = 2
		if mat[6][2] != 5:
			mat[6][2] = 10 - mat[6][2]
		else:
			mat[6][2] = 2
		if mat[7][5] != 5:
			mat[7][5] = 10 - mat[7][5]
		else:
			mat[7][5] = 1
		if mat[8][8] != 5:
			mat[8][8] = 10 - mat[8][8]
		else:
			mat[8][8] = 1
		for i in range(9):
			for j in range(9):
				print(mat[i][j], end='')
			print()
main()


T = int(input())
for _ in range(1, T + 1):
	sudoku = []
	for x in range(9):
		sudoku.append([int(x) for x in input()])
	myList = [[0, 0], [4, 1], [8, 2], [1, 3], [5, 4], [6, 5], [2, 6], [3, 7], [7, 8]]
	for i in myList:
		(x, y) = i
		sudoku[x][y] = 1 if sudoku[x][y] != 1 else 2
	for i in range(len(sudoku)):
		print(''.join((str(sudoku[i][j]) for j in range(9))))


for _ in range(int(input())):
	l = []
	m = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		x = list(input())
		x[m[i]] = str((int(x[m[i]]) + 1) % 9 + 1)
		for i in x:
			print(i, end='')
		print()


t = int(input())
out = ''
d = []
n = 9
d = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
while t > 0:
	t -= 1
	m = []
	for i in range(n):
		m.append([i for i in input()])
	for (x, y) in d:
		m[x][y] = '1' if m[x][y] != '1' else '2'
	for i in range(n):
		for j in range(n):
			out += m[i][j]
		out += '\n'
	out += '\n'
print(out)


t = int(input())
while t:
	a = [input() for _ in range(9)]
	for i in range(9):
		a[i] = a[i].replace('2', '1')
	print(*a, sep='\n')
	t -= 1


def change(e):
	if e == 1:
		return 9
	return e - 1
t = int(input())
for _ in range(t):
	sod = []
	for i in range(9):
		a = list(map(int, [j for j in input()]))
		sod.append(a)
	sod[0][0] = change(sod[0][0])
	sod[1][3] = change(sod[1][3])
	sod[2][6] = change(sod[2][6])
	sod[3][1] = change(sod[3][1])
	sod[4][4] = change(sod[4][4])
	sod[5][7] = change(sod[5][7])
	sod[6][2] = change(sod[6][2])
	sod[7][5] = change(sod[7][5])
	sod[8][8] = change(sod[8][8])
	for i in sod:
		s = ''.join(map(str, i))
		print(s)


t = int(input())
for i in range(0, t):
	a = []
	for k in range(0, 9):
		temp = list(map(int, input().split()))
		output = list(map(int, str(temp[0])))
		a.append(output)
	m = 0
	n = 3
	o = 6
	for i in range(0, 9):
		if i == 0 or i == 3 or i == 6:
			if i == 6:
				new = a[i][m - 1]
				a[i][m] = new
			else:
				new = a[i][m + 1]
				a[i][m] = new
			m += 1
		if i == 1 or i == 4 or i == 7:
			if i == 7:
				new = a[i][n - 1]
				a[i][n] = new
			else:
				new = a[i][n + 1]
				a[i][n] = new
			n += 1
		if i == 2 or i == 5 or i == 8:
			if i == 8:
				new = a[i][o - 1]
				a[i][o] = new
			else:
				new = a[i][o + 1]
				a[i][o] = new
			o += 1
	for i in range(0, 9):
		for k in range(0, 9):
			if k == 8:
				print(a[i][k])
			else:
				print(a[i][k], end='')


from sys import stdin, stdout
from collections import *
from math import ceil, floor, log, gcd
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	s = [st() for i in range(9)]
	s[0][0] = s[0][1]
	s[1][3] = s[1][4]
	s[2][6] = s[2][7]
	s[3][1] = s[3][2]
	s[4][4] = s[4][5]
	s[5][7] = s[5][8]
	s[6][2] = s[6][1]
	s[7][5] = s[7][4]
	s[8][8] = s[8][7]
	for i in s:
		print(''.join(i))
for _ in range(inp()):
	solve()


t = int(input())
for i in range(t):
	sudoku = []
	for j in range(9):
		l = list(input())
		sudoku.append(l)
	sudoku[0][0] = sudoku[0][1]
	sudoku[1][3] = sudoku[1][4]
	sudoku[2][6] = sudoku[2][7]
	sudoku[3][1] = sudoku[3][2]
	sudoku[4][4] = sudoku[4][5]
	sudoku[5][7] = sudoku[5][8]
	sudoku[6][2] = sudoku[6][1]
	sudoku[7][5] = sudoku[7][4]
	sudoku[8][8] = sudoku[8][7]
	for j in sudoku:
		print(*j, sep='')


t = int(input())
for i in range(t):
	a = [input() for i in range(9)]
	for i in range(9):
		a[i] = a[i].replace('1', '2')
	for i in a:
		print(i)


for _ in range(int(input())):
	array = []
	for i in range(9):
		temp = list(map(int, list(input())))
		array.append(temp)
	prev1 = 0
	prev2 = 0
	j = 0
	for i in range(9):
		if array[i][j] == 1:
			array[i][j] = 2
		else:
			array[i][j] = 1
		j = (j + 3) % 9
		if i % 3 == 2:
			j += 1
	for i in range(9):
		temp = map(str, array[i])
		print(''.join(temp))


t = int(input())
while t:
	sud = []
	for i in range(9):
		s = list(str(input()))
		for i in range(0, len(s)):
			if s[i] == '2':
				s[i] = '1'
		sud.append(''.join(s))
	for row in sud:
		print(row)
	t = t - 1


def yo():
	t = int(input())
	for i in range(t):
		for a in range(3):
			for b in range(3):
				line = input()
				print(line[:a + b * 3] + str(int(line[a + b * 3]) % 9 + 1) + line[a + 1 + b * 3:])

def boi():
	t = int(input().strip())
	for i in range(9 * t):
		print(input().strip().replace('1', '2'))

def soy():
	t = int(input())
	for i in range(t):
		l = [input().replace('1', '2') for j in range(9)]
		print('\n'.join(l))
soy()


for _ in range(int(input())):
	k = [list(map(lambda i: int(i), list(input()))) for i in range(9)]
	r = 0
	for i in range(0, 9, 3):
		t = i
		for j in range(r, 9, 3):
			if k[t][j] == 5:
				k[t][j] = 9 - k[t][j]
			else:
				k[t][j] = 10 - k[t][j]
			t += 1
		r += 1
	for p in k:
		q = list(map(lambda m: str(m), p))
		print(''.join(q))


for case in range(int(input())):
	l = [[] for i in range(9)]
	for i in range(9):
		l[i] = list(input())
		for j in range(9):
			l[i][j] = int(l[i][j])
			if l[i][j] == 3:
				l[i][j] = 9
	for i in range(9):
		tmp = ''
		for j in range(9):
			tmp += str(l[i][j])
		print(tmp)


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
from collections import Counter
for _ in range(I()[0]):
	a = []
	for i in range(9):
		a.append([int(i) for i in input()])
	a[0][0] = a[0][1]
	a[1][3] = a[1][4]
	a[2][6] = a[2][8]
	a[3][1] = a[3][2]
	a[4][4] = a[4][5]
	a[5][7] = a[5][8]
	a[6][2] = a[6][1]
	a[7][5] = a[7][4]
	a[8][8] = a[8][7]
	for i in range(9):
		print(''.join(map(str, a[i])))


t = int(input())
for t1 in range(t):
	a = []
	for i in range(9):
		sud = list(input())
		a.append(sud)
	a[0][8] = a[0][7]
	a[1][5] = a[1][4]
	a[2][2] = a[2][1]
	a[3][7] = a[3][6]
	a[4][4] = a[4][3]
	a[5][1] = a[4][0]
	a[6][6] = a[6][5]
	a[7][3] = a[7][2]
	a[8][0] = a[8][1]
	for x in a:
		print(*x, sep='')


def foo():
	sudoku = []
	for i in range(9):
		temp = input()
		t2 = []
		for i in temp:
			t2.append(i)
		sudoku.append(t2)
	for i in range(3):
		sudoku[i * 3][i] = sudoku[i * 3][(i + 1) % 3]
		sudoku[i * 3 + 1][i + 3] = sudoku[i * 3 + 1][(i + 1) % 3 + 3]
		sudoku[i * 3 + 2][i + 6] = sudoku[i * 3 + 2][(i + 1) % 3 + 6]
	for i in sudoku:
		for j in i:
			print(j, end='')
		print()
t = int(input())
for i in range(t):
	foo()


import sys
input = sys.stdin.readline

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

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

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

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	res = []
	s = getStr()
	res.append(s[1] + s[1:])
	s = getStr()
	res.append(s[:3] + s[4] + s[4:])
	s = getStr()
	res.append(s[:6] + s[7] + s[7:])
	s = getStr()
	res.append(s[:1] + s[2] + s[2:])
	s = getStr()
	res.append(s[:4] + s[5] + s[5:])
	s = getStr()
	res.append(s[:7] + s[8] + s[8:])
	s = getStr()
	res.append(s[:2] + s[0] + s[3:])
	s = getStr()
	res.append(s[:5] + s[3] + s[6:])
	s = getStr()
	res.append(s[:8] + s[6])
	for i in range(9):
		print(res[i])


for _ in range(int(input())):
	b = []
	for i in range(9):
		a = list(input())
		b.append(a)
	b[0][0] = b[1][0]
	b[1][3] = b[0][3]
	b[2][6] = b[1][6]
	b[3][1] = b[4][1]
	b[4][4] = b[3][4]
	b[5][7] = b[4][7]
	b[6][2] = b[7][2]
	b[7][5] = b[6][5]
	b[8][8] = b[7][8]
	for i in range(9):
		print(''.join(b[i]))


t = int(input())
for _ in range(t):
	puzzle = []
	for _ in range(9):
		p = [x for x in input()]
		puzzle.append(p)
	change = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
	for c in change:
		(h, w) = c
		if int(puzzle[h][w]) < 9:
			puzzle[h][w] = str(int(puzzle[h][w]) + 1)
		else:
			puzzle[h][w] = '1'
	for p in puzzle:
		print(''.join(p))


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	A = [list(map(int, list(input().strip()))) for i in range(9)]
	for i in range(9):
		for j in range(9):
			if A[i][j] == 1:
				if j % 3 != 2:
					A[i][j + 1] = 1
					break
				else:
					A[i][j - 2] = 1
					break
	for i in range(9):
		print(''.join(map(str, A[i])))


t = int(input())
ys = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for a in ys:
	a -= 1
for i in range(t):
	ls = []
	for j in range(9):
		ss = input()
		ls1 = []
		for a in ss:
			ls1.append(int(a))
		ls.append(ls1)
	for j in range(9):
		if j == 8:
			p = 0
		else:
			p = j + 1
		ls[j][ys[j]] = ls[p][ys[j]]
	for a in ls:
		for b in a:
			print(b, end='')
		print('\n')


n_cases = int(input())
for case_num in range(1, n_cases + 1):
	grid = [[int(x) for x in input()] for _ in range(9)]
	assert len(grid) == 9
	for set_idx in range(3):
		for block_idx in range(3):
			grid[3 * set_idx + block_idx][3 * block_idx + set_idx] = (grid[3 * set_idx + block_idx][3 * block_idx + set_idx] + 1) % 9
			if grid[3 * set_idx + block_idx][3 * block_idx + set_idx] == 0:
				grid[3 * set_idx + block_idx][3 * block_idx + set_idx] = 1
	for row in grid:
		print(''.join([str(x) for x in row]))


def morph(v):
	if int(v) // 2 == 0:
		return str(int(v) * 2)
	return str(int(v) // 2)
cases = int(input())
for t in range(cases):
	a = []
	for i in range(9):
		a.append(list(input()))
	a[0][0] = morph(a[0][0])
	a[1][3] = morph(a[1][3])
	a[2][6] = morph(a[2][6])
	a[3][1] = morph(a[3][1])
	a[4][4] = morph(a[4][4])
	a[5][7] = morph(a[5][7])
	a[6][2] = morph(a[6][2])
	a[7][5] = morph(a[7][5])
	a[8][8] = morph(a[8][8])
	for i in a:
		print(''.join(i))


t = int(input())
for _ in range(t):
	arr = [[0 for i in range(10)] for j in range(10)]
	for i in range(1, 10):
		s = input()
		for j in range(1, 10):
			arr[i][j] = ord(s[j - 1]) - ord('0')
	arr[1][1] = arr[2][1]
	arr[2][4] = arr[3][4]
	arr[3][7] = arr[1][7]
	arr[4][2] = arr[5][2]
	arr[5][5] = arr[6][5]
	arr[6][8] = arr[4][8]
	arr[7][3] = arr[8][3]
	arr[8][6] = arr[9][6]
	arr[9][9] = arr[7][9]
	for i in range(1, 10):
		for j in range(1, 10):
			print(arr[i][j], end='')
		print()


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def I():
	return int(input())

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

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		for _ in range(I()):
			l = []
			for i in range(9):
				l.append(list(map(int, list(input()))))
			if l[0][0] == 1:
				l[0][0] = 2
			else:
				l[0][0] -= 1
			if l[1][3] == 1:
				l[1][3] = 2
			else:
				l[1][3] -= 1
			if l[2][6] == 1:
				l[2][6] = 2
			else:
				l[2][6] -= 1
			if l[3][1] == 1:
				l[3][1] = 2
			else:
				l[3][1] -= 1
			if l[4][4] == 1:
				l[4][4] = 2
			else:
				l[4][4] -= 1
			if l[5][7] == 1:
				l[5][7] = 2
			else:
				l[5][7] -= 1
			if l[6][2] == 1:
				l[6][2] = 2
			else:
				l[6][2] -= 1
			if l[7][5] == 1:
				l[7][5] = 2
			else:
				l[7][5] -= 1
			if l[8][8] == 1:
				l[8][8] = 2
			else:
				l[8][8] -= 1
			for i in range(9):
				for j in range(9):
					print(l[i][j], end='')
				print()
	except:
		pass
M = 998244353
P = 1000000007
main()


for _ in range(int(input())):
	for i in range(9):
		s = input()
		d = ''
		for i in s:
			if i == '2':
				d = d + '1'
			else:
				d = d + i
		print(d)


for _ in range(int(input())):
	m = [list(input()) for _ in range(9)]
	p = [(0, 0), (1, 4), (3, 1), (5, 6), (7, 3), (8, 7)]
	q = [(2, 8), (4, 5), (6, 2)]
	for (i, j) in p:
		m[i][j] = m[i][j + 1]
	for (i, j) in q:
		m[i][j] = m[i][j - 1]
	for i in m:
		print(''.join(i))


INT_MAX = 10 ** 18 + 7
x = 10 ** 9 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]
GETA = 123
for _ in range(int(input())):
	B = []
	for j in range(9):
		A = input()
		X = list(A)
		for i in range(9):
			if A[i] == '1':
				X[i] = '2'
				break
		B.append(X)
	for i in range(9):
		for j in range(9):
			print(B[i][j], end='')
		print()


for _ in range(int(input())):
	a = [list(input()) for x in range(9)]
	for x in range(0, 9, 3):
		for y in range(0, 9, 3):
			chk = 0
			for sx in range(x, x + 3):
				for sy in range(y, y + 3):
					if a[sx][sy] == '1':
						if sx + 1 == x + 3:
							a[x][sy] = '1'
							chk = 1
							break
						else:
							chk = 1
							a[sx + 1][sy] = '1'
							break
				if chk == 1:
					break
	for x in a:
		print(*x, sep='')


t = int(input())
for _ in range(t):
	lst = []
	for i in range(9):
		ele = str(input())
		ele = ele.replace('1', '9')
		lst.append(ele)
	for i in lst:
		print(i)


def answer(t):
	for i in range(t):
		a = []
		for i in range(9):
			a.append(list(map(int, list(input()))))
		l = 0
		k = 0
		for i in range(9):
			j = l + k
			if a[i][j] != 9:
				a[i][j] += 1
			else:
				a[i][j] = 1
			if i % 3 == 2:
				l += 1
				k = 0
			else:
				k += 3
		for i in a:
			print(''.join(map(str, i)))
answer(int(input()))


t = int(input())
for tt in range(t):
	l = []
	for i in range(9):
		s = input()
		ll = []
		for i in s:
			ll.append(int(i))
		l.append(ll)
	for i in range(9):
		for j in range(9):
			if l[i][j] == 1:
				l[i][j] = 3
	ss = []
	for i in range(9):
		sx = ''
		for j in range(9):
			sx += str(l[i][j])
		ss.append(sx)
	for i in range(9):
		print(ss[i])


t = int(input())
all_matrix = []
for _ in range(t):
	matrix = []
	for i in range(9):
		row = list(map(int, input()))
		matrix.append(row)
		for j in range(9):
			if matrix[i][j] == 2:
				matrix[i][j] = 1
	all_matrix.append(matrix)
for mx in all_matrix:
	for row in mx:
		print(''.join(map(str, row)))


t = int(input())
while t:
	arr = []
	for i in range(9):
		a = input()
		a = list(a)
		arr.append(list(map(int, a)))
		k = 0
		i = 0
		j = k
	while i < 9:
		if arr[i][j] < 9:
			arr[i][j] += 1
		else:
			arr[i][j] = 1
		j += 3
		i += 1
		if j >= 9:
			k += 1
			j = k
	for i in range(9):
		for j in range(9):
			print(arr[i][j], end='')
		print()
	t -= 1


import math
t = int(input())

def print_fn(arr):
	for j in arr:
		print(j, end='')
	print()
for i in range(t):
	arr = list(input())
	arr[0] = str(math.ceil((int(arr[0]) + 1) % 9.5))
	print_fn(arr)
	arr = list(input())
	arr[3] = str(math.ceil((int(arr[3]) + 1) % 9.5))
	print_fn(arr)
	arr = list(input())
	arr[6] = str(math.ceil((int(arr[6]) + 1) % 9.5))
	print_fn(arr)
	arr = list(input())
	arr[1] = str(math.ceil((int(arr[1]) + 1) % 9.5))
	print_fn(arr)
	arr = list(input())
	arr[4] = str(math.ceil((int(arr[4]) + 1) % 9.5))
	print_fn(arr)
	arr = list(input())
	arr[7] = str(math.ceil((int(arr[7]) + 1) % 9.5))
	print_fn(arr)
	arr = list(input())
	arr[2] = str(math.ceil((int(arr[2]) + 1) % 9.5))
	print_fn(arr)
	arr = list(input())
	arr[5] = str(math.ceil((int(arr[5]) + 1) % 9.5))
	print_fn(arr)
	arr = list(input())
	arr[8] = str(math.ceil((int(arr[8]) + 1) % 9.5))
	print_fn(arr)


from math import floor, ceil
t = int(input())
ans = []
for _ in range(t):
	s = ''
	for i in range(9):
		s += input() + '\n'
	ans.append(s.replace('9', '1'))
print(*ans, sep='\n')


t = int(input())
for _ in range(t):
	sud = []
	for i in range(9):
		sud.append(list(input().strip()))
	coord = [(1, 1), (2, 4), (3, 7), (4, 2), (5, 5), (6, 8), (7, 3), (8, 6), (9, 9)]
	for (x, y) in coord:
		x -= 1
		y -= 1
		if sud[x][y] != '1':
			sud[x][y] = '1'
		else:
			sud[x][y] = '2'
	for r in sud:
		print(''.join(r))


t = int(input())
for i in range(t):
	row = [None for i in range(9)]
	for j in range(9):
		row[j] = input()
		row[j] = list(row[j])
	row[0][0] = row[0][1]
	row[1][3] = row[1][4]
	row[2][6] = row[2][7]
	row[3][1] = row[3][2]
	row[4][4] = row[4][5]
	row[5][7] = row[5][8]
	row[6][2] = row[6][3]
	row[7][5] = row[7][6]
	row[8][8] = row[8][0]
	for j in range(9):
		for k in range(9):
			print(row[j][k], end='')
		print('')


t = int(input())
for rep in range(t):
	a = []
	for rep2 in range(9):
		a.append(list(input()))
	a[0][0] = str(int(a[0][0]) % 9 + 1)
	a[1][3] = str(int(a[1][3]) % 9 + 1)
	a[2][6] = str(int(a[2][6]) % 9 + 1)
	a[3][1] = str(int(a[3][1]) % 9 + 1)
	a[4][4] = str(int(a[4][4]) % 9 + 1)
	a[5][7] = str(int(a[5][7]) % 9 + 1)
	a[6][2] = str(int(a[6][2]) % 9 + 1)
	a[7][5] = str(int(a[7][5]) % 9 + 1)
	a[8][8] = str(int(a[8][8]) % 9 + 1)
	for rep3 in range(9):
		print(''.join(a[rep3]))


t = int(input())
for i in range(t):
	for j in range(9):
		s = ''
		n = input()
		for k in range(9):
			if j == 0 and k == 0:
				s = s + n[k + 1]
			elif j == 1 and k == 3:
				s = s + n[k + 1]
			elif j == 2 and k == 6:
				s = s + n[k + 1]
			elif j == 3 and k == 1:
				s = s + n[k + 1]
			elif j == 4 and k == 4:
				s = s + n[k + 1]
			elif j == 5 and k == 7:
				s = s + n[k + 1]
			elif j == 6 and k == 2:
				s = s + n[k + 1]
			elif j == 7 and k == 5:
				s = s + n[k + 1]
			elif j == 8 and k == 8:
				s = s + n[7]
			else:
				s = s + n[k]
		print(s)


def yo():
	t = int(input())
	for i in range(t):
		for a in range(3):
			for b in range(3):
				line = input()
				print(line[:a + b * 3] + str(int(line[a + b * 3]) % 9 + 1) + line[a + 1 + b * 3:])
yo()


for _ in range(int(input())):
	for i in [0, 3, 6, 1, 4, 7, 2, 5, 8]:
		p = list(input())
		p[i] = '1' if p[i] != '1' else '2'
		print(''.join(p))


def change(n):
	if n == 1:
		return n + 1
	else:
		return n - 1
T = int(input())
for t in range(0, T):
	sudoku = []
	for i in range(0, 9):
		line = input()
		current = []
		for num in line:
			current.append(int(num))
		sudoku.append(current)
	sudoku[0][0] = change(sudoku[0][0])
	sudoku[1][3] = change(sudoku[1][3])
	sudoku[2][6] = change(sudoku[2][6])
	sudoku[3][1] = change(sudoku[3][1])
	sudoku[4][4] = change(sudoku[4][4])
	sudoku[5][7] = change(sudoku[5][7])
	sudoku[6][2] = change(sudoku[6][2])
	sudoku[7][5] = change(sudoku[7][5])
	sudoku[8][8] = change(sudoku[8][8])
	for a in range(0, 9):
		line = ''
		for b in range(0, 9):
			line += str(sudoku[a][b])
		print(line)
	print('\n')


import sys
t = int(input())
for x in range(t):
	S = []
	for y in range(9):
		l = list(map(int, input()))
		S.append(l)
	for k in range(len(S)):
		if k == 0:
			if S[k][0] == 1:
				S[k][0] = 2
			else:
				S[k][0] = 1
		if k == 1:
			if S[k][3] == 1:
				S[k][3] = 2
			else:
				S[k][3] = 1
		if k == 2:
			if S[k][6] == 1:
				S[k][6] = 2
			else:
				S[k][6] = 1
		if k == 3:
			if S[k][1] == 1:
				S[k][1] = 2
			else:
				S[k][1] = 1
		if k == 4:
			if S[k][4] == 1:
				S[k][4] = 2
			else:
				S[k][4] = 1
		if k == 5:
			if S[k][7] == 1:
				S[k][7] = 2
			else:
				S[k][7] = 1
		if k == 6:
			if S[k][2] == 1:
				S[k][2] = 2
			else:
				S[k][2] = 1
		if k == 7:
			if S[k][5] == 1:
				S[k][5] = 2
			else:
				S[k][5] = 1
		if k == 8:
			if S[k][8] == 1:
				S[k][8] = 2
			else:
				S[k][8] = 1
	for k in range(len(S)):
		for i in S[k]:
			print(i, end='')
		print()


import sys
e = int(input())
for ee in range(e):
	u = []
	for i in range(9):
		j = str(input())
		u.append(j)
	a = []
	for i in range(9):
		b = []
		for j in range(9):
			b.append(0)
		a.append(b)
	for i in range(9):
		for j in range(9):
			a[i][j] = int(u[i][j])
	for i in range(9):
		if i == 0:
			if a[0][0] + 1 == 10:
				a[0][0] = 1
			else:
				a[0][0] += 1
		if i == 1:
			if a[3][1] + 1 == 10:
				a[3][1] = 1
			else:
				a[3][1] += 1
		if i == 2:
			if a[8][2] + 1 == 10:
				a[8][2] = 1
			else:
				a[8][2] += 1
		if i == 3:
			if a[1][3] + 1 == 10:
				a[1][3] = 1
			else:
				a[1][3] += 1
		if i == 4:
			if a[4][4] + 1 == 10:
				a[4][4] = 1
			else:
				a[4][4] += 1
		if i == 5:
			if a[7][5] + 1 == 10:
				a[7][5] = 1
			else:
				a[7][5] += 1
		if i == 6:
			if a[2][6] + 1 == 10:
				a[2][6] = 1
			else:
				a[2][6] += 1
		if i == 7:
			if a[5][7] + 1 == 10:
				a[5][7] = 1
			else:
				a[5][7] += 1
		if i == 8:
			if a[6][8] + 1 == 10:
				a[6][8] = 1
			else:
				a[6][8] += 1
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


def anti_sudoku(sudoku):
	points_to_change = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
	for (x, y) in points_to_change:
		sudoku[x][y] = anti_number(sudoku[x][y])
	return '\n'.join([''.join([str(e) for e in arr]) for arr in sudoku])

def anti_number(number):
	return number + 1 if number < 9 else 1
res = ''
for _ in range(int(input())):
	sudoku = []
	for _ in range(9):
		sudoku.append([int(e) for e in list(input())])
	res += anti_sudoku(sudoku) + '\n'
print(res, sep='')


import collections

def solve(sudoku):
	for i in range(9):
		for j in range(9):
			if sudoku[i][j] == 2:
				sudoku[i][j] = 1
	for row in sudoku:
		print(''.join(map(str, row)))
t = int(input().strip())
for i in range(t):
	sudoku = []
	for _ in range(9):
		sudoku.append([int(ch) for ch in input().strip()])
	solve(sudoku)


def distribution(n):
	return (n - 1) // 2

def problem_A():
	print(distribution(int(input())))
s = 'abcdefghijklmnopqrstuvwxyz'

def cons_str(n, b):
	a = s[:b]
	ans = ''
	while n > b:
		ans += a
		n -= b
	ans += a[:n]
	return ans

def problem_B():
	(n, a, b) = list(map(int, input().split()))
	print(cons_str(n, b))

def comp_teams(a):
	if len(a) < 2:
		return 0
	s = len(set(a))
	if s == len(a):
		return 1
	a.sort()
	t = 0
	temp = 1
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			temp += 1
		else:
			if t < temp:
				t = temp
			temp = 1
	if t < temp:
		t = temp
	if s <= t - 1:
		return s
	if s == t:
		return s - 1
	else:
		return t

def problem_C():
	l = int(input())
	a = list(map(int, input().split()))
	print(comp_teams(a))

def antisudoku(a):
	for i in range(9):
		for j in range(9):
			if a[i][j] == '2':
				a[i][j] = '1'
	return a

def problem_D():
	a = []
	for _ in range(9):
		a.append(list(input()))
	b = antisudoku(a)
	for i in range(9):
		print(''.join(b[i]))

def three_block_palindrome(s):
	a = []
	b = []
	c = []
	l = len(s)
	for _ in range(l):
		a = []
		for _ in range(l + 1):
			a.append([0] * 26)
	l += 1
	for i in range(1, l):
		k = s[i - 1] - 1
		for j in range(26):
			a[i][j] = a[i - 1][j]
		a[i][k] += 1
	maxlength = 0
	for i in range(l):
		for j in range(i, l):
			maxa = 0
			maxb = 0
			for k in range(26):
				if a[l - 1][k] - a[j][k] > a[i][k]:
					if maxa < a[i][k]:
						maxa = a[i][k]
				elif maxa < a[l - 1][k] - a[j][k]:
					maxa = a[l - 1][k] - a[j][k]
				if maxb < a[j][k] - a[i][k]:
					maxb = a[j][k] - a[i][k]
			if maxlength < 2 * maxa + maxb:
				maxlength = 2 * maxa + maxb
	return maxlength

def problem_E1():
	l = int(input())
	s = list(map(int, input().split()))
	print(three_block_palindrome(s))
cases = int(input())
for _ in range(cases):
	problem_D()


t = int(input())
mat = []
indices = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for _ in range(t):
	for k in range(9):
		temp = input()
		row = [char for char in temp]
		if row[indices[k]] != '9':
			row[indices[k]] = '9'
		else:
			row[indices[k]] = '1'
		mat.append(''.join(row))
for row in mat:
	print(row)


n = 9
for _ in range(int(input())):
	g = []
	for i in range(n):
		c = list(input())
		g.append(c)
	for k in range(n):
		if k == 0:
			g[0][0] = ['1', '2'][g[0][0] == '1']
		if k == 1:
			g[1][4] = ['1', '2'][g[1][4] == '1']
		if k == 2:
			g[2][8] = ['1', '2'][g[2][8] == '1']
		if k == 3:
			g[3][1] = ['1', '2'][g[3][1] == '1']
		if k == 4:
			g[4][3] = ['1', '2'][g[4][3] == '1']
		if k == 5:
			g[5][6] = ['1', '2'][g[5][6] == '1']
		if k == 6:
			g[6][2] = ['1', '2'][g[6][2] == '1']
		if k == 7:
			g[7][5] = ['1', '2'][g[7][5] == '1']
		if k == 8:
			g[8][7] = ['1', '2'][g[8][7] == '1']
	for i in g:
		print(*i, sep='')


from collections import deque
import math
n = int(input())
for i in range(n * 9):
	str1 = str(input())
	print(str1.replace('1', '2'))


from collections import Counter
for _ in range(int(input())):
	grid = []
	for i in range(9):
		grid.append([int(c) for c in input()])
	for i in range(3):
		grid[3 * i + 1][0 + i] = grid[3 * i + 0][0 + i]
		grid[3 * i + 2][3 + i] = grid[3 * i + 1][3 + i]
		grid[3 * i + 0][6 + i] = grid[3 * i + 2][6 + i]
	for li in grid:
		print(''.join([str(i) for i in li]))


t = int(input())
for _ in range(t):
	s = [list(map(int, list(input()))) for _ in range(9)]
	ch = (0, 3, 6, 1, 4, 7, 2, 5, 8)
	for i in range(9):
		s[i][ch[i]] += 1
		if s[i][ch[i]] == 10:
			s[i][ch[i]] = 1
	for j in range(9):
		for k in range(9):
			print(s[j][k], end='')
		print()


t = int(input())
l = []
for i in range(t):
	l1 = []
	for j in range(9):
		s = input()
		l1.append(s)
	l.append(l1)
for p in l:
	print(p[0].replace(p[0][1], p[0][0]))
	print(p[1].replace(p[1][4], p[1][3]))
	print(p[2].replace(p[2][7], p[2][6]))
	print(p[3].replace(p[3][2], p[3][1]))
	print(p[4].replace(p[4][5], p[4][4]))
	print(p[5].replace(p[5][8], p[5][7]))
	print(p[6].replace(p[6][0], p[6][1]))
	print(p[7].replace(p[7][3], p[7][4]))
	print(p[8].replace(p[8][6], p[8][7]))


t = int(input())
while t > 0:
	j = 0
	sudoku = []
	while j < 9:
		st = input()
		sudoku.append(list(st))
		j += 1
	num = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
	i = 0
	pos = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for index in pos:
		ch = sudoku[index[0]][index[1]]
		for ele in num:
			if ele != ch:
				break
		sudoku[index[0]][index[1]] = ele
	for ele in sudoku:
		print(''.join(ele))
	t -= 1


def solve(arr, ans):
	col = 0
	for row in range(1, 10):
		if row % 3 == 1:
			col += 1
			col1 = col
		arr[row - 1][col1 - 1] = max(9 - arr[row - 1][col1 - 1], 1)
		col1 += 3
	for i in arr:
		s = ''
		for j in i:
			s += str(j)
		ans.append(s)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		arr = []
		for j in range(9):
			arr.append(list(map(int, input())))
		solve(arr, ans)
	for i in ans:
		print(i)
main()


for i in range(int(input())):
	sudo = []
	for j in range(9):
		a = input()
		row = []
		new_row = []
		for i in a:
			row.append(int(i))
		for m in range(9):
			if row[m] == 1:
				row[m] = 2
		for k in row:
			new = str(k)
			new_row.append(new)
		sudo.append(new_row)
	for e in sudo:
		print(''.join(e))


for _ in range(int(input())):
	sudoku = []
	for i in range(9):
		sudoku.append(list(input()))
	indices = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for (x, y) in indices:
		el = int(sudoku[x][y])
		sudoku[x][y] = str((el + 1) % 9 + 1)
	for i in sudoku:
		print(''.join(i))


import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

def instr():
	s = input()
	return list(s[:len(s)])

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

def def_value():
	return False

def find_x(p, r):
	look = [0] * 10
	x = r[0]
	y = r[1]
	for i in range(x[0], y[0] + 1):
		for j in range(x[1], y[1] + 1):
			look[a[i][j]] += 1
	backup = -1
	for songka in range(1, 10):
		temp11 = -1
		for i in range(9):
			temp1 = a[p[0]][i]
			if temp1 == songka and i != p[1]:
				temp11 = temp1
				break
		if temp11 == -1:
			continue
		temp22 = -2
		for i in range(9):
			temp2 = a[i][p[1]]
			if temp2 == songka and i != p[0]:
				temp22 = temp2
				break
		if temp11 == temp22:
			backup = temp22
			if look[temp11] > 0:
				return temp11
	return backup
t = inp()
for _ in range(t):
	a = []
	for i in range(9):
		temp = instr()
		temp = list(map(int, temp))
		a.append(temp)
	index = [[0, 0], [3, 1], [6, 2], [1, 3], [4, 4], [7, 5], [2, 6], [5, 7], [8, 8]]
	Range = [[[0, 0], [2, 2]], [[3, 0], [5, 2]], [[6, 0], [8, 2]], [[0, 3], [2, 5]], [[3, 3], [5, 5]], [[6, 3], [8, 5]], [[6, 0], [2, 8]], [[3, 6], [5, 7]], [[6, 6], [8, 8]]]
	for i in range(9):
		x = find_x(index[i], Range[i])
		temp = index[i]
		a[temp[0]][temp[1]] = x
	for i in a:
		for c in i:
			print(c, end='')
		print()


t = int(input())
for _ in range(t):
	i = 0
	for _ in range(9):
		for ch in input():
			print('1' if ch == '2' else ch, end='')
		print('')


for _ in range(int(input())):
	l = []
	arr = [0, 3, 6]
	for i in range(9):
		t = list(input())
		if i == 8:
			t[arr[i % 3] + i // 3] = t[arr[i % 3] + i // 3 - 1]
		else:
			t[arr[i % 3] + i // 3] = t[arr[i % 3] + i // 3 + 1]
		l.append(t)
	for i in l:
		print(''.join(i))


from itertools import groupby
t = int(input())
for i in range(t):
	grid = []
	for j in range(9):
		row = [int(v) for v in input()]
		grid.append(row)
	points = [(0, 0), (1, 4), (2, 8), (3, 1), (4, 7), (5, 3), (6, 2), (7, 5), (8, 6)]
	for (r, c) in points:
		v = grid[r][c]
		grid[r][c] = 2 if v == 1 else 1
	for row in grid:
		print(''.join((str(v) for v in row)))


import sys
import io, os

def main():
	input = sys.stdin.readline
	t = int(input())
	for i in range(t):
		sudoku = []
		for i in range(9):
			r = [int(i) for i in input() if i != '\n']
			sudoku.append(r)
		sudoku[0][0] = sudoku[0][0] + 1
		if sudoku[0][0] == 10:
			sudoku[0][0] = 1
		sudoku[1][3] = sudoku[1][3] + 1
		if sudoku[1][3] == 10:
			sudoku[1][3] = 1
		sudoku[2][6] = sudoku[2][6] + 1
		if sudoku[2][6] == 10:
			sudoku[2][6] = 1
		sudoku[3][1] = sudoku[3][1] + 1
		if sudoku[3][1] == 10:
			sudoku[3][1] = 1
		sudoku[4][4] = sudoku[4][4] + 1
		if sudoku[4][4] == 10:
			sudoku[4][4] = 1
		sudoku[5][7] = sudoku[5][7] + 1
		if sudoku[5][7] == 10:
			sudoku[5][7] = 1
		sudoku[6][2] = sudoku[6][2] + 1
		if sudoku[6][2] == 10:
			sudoku[6][2] = 1
		sudoku[7][5] = sudoku[7][5] + 1
		if sudoku[7][5] == 10:
			sudoku[7][5] = 1
		sudoku[8][8] = sudoku[8][8] + 1
		if sudoku[8][8] == 10:
			sudoku[8][8] = 1
		for i in sudoku:
			i = ''.join(map(str, i))
			sys.stdout.write(i + '\n')
main()


t = int(input())
for _ in range(t):
	sudoku = []
	for i in range(9):
		grid = [int(p) for p in list(input())]
		sudoku.append(grid)
	loc = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for i in range(len(loc)):
		(x, y) = loc[i]
		if sudoku[x][y] != 5:
			sudoku[x][y] = 10 - sudoku[x][y]
		else:
			sudoku[x][y] = 4
	final = []
	for i in range(len(sudoku)):
		row = ''.join([str(p) for p in sudoku[i]])
		final.append(row)
	for i in final:
		print(i)


t = int(input())
ans = []
for i in range(t):
	ans.append([''] * 9)
	for j in range(9):
		ans[i][j] = input().replace('9', '1')
for x in ans:
	for y in x:
		print(y)


for _ in range(int(input())):
	l1 = []
	for i in range(9):
		l1.append(list(input()))
	l1[0][0] = l1[0][1]
	l1[1][3] = l1[1][4]
	l1[2][6] = l1[2][7]
	l1[3][1] = l1[3][2]
	l1[4][4] = l1[4][5]
	l1[5][7] = l1[5][8]
	l1[6][2] = l1[6][3]
	l1[7][5] = l1[7][6]
	l1[8][8] = l1[8][7]
	for item in l1:
		for i in item:
			print(i, end='')
		print()


t = int(input())
for i in range(t):
	sudoku = []
	for i in range(9):
		a = list(input())
		for i in range(len(a)):
			a[i] = int(a[i])
		sudoku.append(a)
	sw = [(0, 0), (1, 4), (2, 8), (3, 6), (4, 1), (5, 5), (6, 2), (7, 7), (8, 3)]
	for i in range(9):
		(now1, now2) = sw[i]
		if sudoku[now1][now2] != 5:
			sudoku[now1][now2] = 10 - sudoku[now1][now2]
		else:
			sudoku[now1][now2] = 1
	for i in range(9):
		for i in sudoku[i]:
			print(i, end='')
		print()


t = eval(input())
for k in range(0, t):
	for i in range(0, 9):
		str = input()
		for j in range(0, 9):
			if str[j] == '1':
				print('2', end='')
			else:
				print(str[j], end='')
		print()


import sys, bisect
from collections import defaultdict
input = sys.stdin.readline

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

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

def insr():
	s = input().rstrip()
	return s[:len(s) - 1]

def invr():
	return map(int, input().rstrip().split())
t = inp()
for _ in range(t):
	nums = [[0 for j in range(9)] for i in range(9)]
	for i in range(9):
		s = input().rstrip()
		for j in range(9):
			nums[i][j] = int(s[j])
	pos = [(0, 0), (1, 4), (2, 8), (3, 1), (5, 3), (4, 6), (6, 2), (7, 5), (8, 7)]
	for each in pos:
		(row, col) = each
		if nums[row][col] != 1:
			nums[row][col] = 1
		else:
			nums[row][col] = 2
	for i in range(9):
		print(''.join((str(i) for i in nums[i])))


for t in range(int(input())):
	sud = []
	for i in range(9):
		sud.append(list(map(int, list(input()))))
	x = [0, 1, 2, 3, 4, 5, 6, 7, 8]
	y = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		if sud[x[i]][y[i]] == 9:
			sud[x[i]][y[i]] -= 1
		else:
			sud[x[i]][y[i]] += 1
	for i in range(9):
		for j in range(9):
			print(sud[i][j], end='')
		print()


import string

def other(a):
	if a == '1':
		return '2'
	else:
		return '1'

def changeStr(s, i):
	return s[:i] + other(s[i]) + s[i + 1:]
n = int(input())
for _ in range(n):
	sodoku = []
	for i in range(9):
		sodoku.append(input())
	sodoku[0] = changeStr(sodoku[0], 0)
	sodoku[1] = changeStr(sodoku[1], 3)
	sodoku[2] = changeStr(sodoku[2], 6)
	sodoku[3] = changeStr(sodoku[3], 1)
	sodoku[4] = changeStr(sodoku[4], 4)
	sodoku[5] = changeStr(sodoku[5], 7)
	sodoku[6] = changeStr(sodoku[6], 2)
	sodoku[7] = changeStr(sodoku[7], 5)
	sodoku[8] = changeStr(sodoku[8], 8)
	for i in range(9):
		out = ''
		for j in range(9):
			out += sodoku[i][j]
		print(out)


n = int(input())
for _ in range(n):
	sd = [[0] * 9 for _ in range(9)]
	for i in range(9):
		a = input()
		for j in range(9):
			sd[i][j] = int(a[j])
			if sd[i][j] == 1:
				sd[i][j] = 2
	for i in range(9):
		print(*sd[i], sep='')


n = int(input())
for k in range(n):
	A = []
	for i in range(9):
		A.append(input())
	j = 0
	t = 0
	for i in range(9):
		print(A[i][0:j], end='')
		tmp = int(A[i][j]) + 1
		if tmp == 10:
			tmp = 1
		print(tmp, end='')
		print(A[i][j + 1:9])
		j = (j + 3) % 9
		t += 1
		if t % 3 == 0:
			j = (j + 1) % 9


def main():
	cases = int(input())
	for case in range(cases):
		l = []
		for i in range(9):
			l.append(list(map(int, list(input()))))
		idxs = [(0, 0), (1, 4), (2, 8), (4, 1), (5, 5), (3, 6), (8, 2), (6, 3), (7, 7)]
		nums = set()
		for idx in idxs:
			nums.add(l[idx[0]][idx[1]])
		rep = -1
		if len(nums) < 9:
			for i in range(1, 10):
				if i not in nums:
					rep = i
					break
		else:
			rep = l[0][0]
		for idx in idxs:
			l[idx[0]][idx[1]] = rep
		if len(nums) == 9:
			if l[0][0] == 9:
				l[0][0] = 1
			else:
				l[0][0] += 1
		for i in l:
			print(''.join(map(str, i)))
main()


def anti_Sudoku(sudoku):
	(index, offset) = (0, 0)
	for x in range(9):
		sudoku[x][index] = sudoku[x][-1]
		index += 3
		if index >= 9:
			offset += 1
			index = offset
	sudoku[-1][-1] = sudoku[-1][0]
for _ in range(int(input())):
	array = []
	for b in range(9):
		array.append([n for n in input()])
	anti_Sudoku(array)
	for x in array:
		print(''.join((str(j) for j in x)))


for i in range(int(input())):
	a = input()
	print(a[0] + a[0] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8])
	a = input()
	print(a[0] + a[1] + a[2] + a[3] + a[3] + a[5] + a[6] + a[7] + a[8])
	a = input()
	print(a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[6] + a[8])
	a = input()
	print(a[0] + a[1] + a[1] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8])
	a = input()
	print(a[0] + a[1] + a[2] + a[3] + a[4] + a[4] + a[6] + a[7] + a[8])
	a = input()
	print(a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[7])
	a = input()
	print(a[0] + a[1] + a[2] + a[2] + a[4] + a[5] + a[6] + a[7] + a[8])
	a = input()
	print(a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[5] + a[7] + a[8])
	a = input()
	print(a[8] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8])


for _ in range(int(input())):
	a = []
	for i in range(9):
		b = [int(d) for d in input()]
		a.append(b)
	a[0][0] = a[0][1]
	a[3][1] = a[3][2]
	a[6][2] = a[6][1]
	a[1][3] = a[1][4]
	a[4][4] = a[4][5]
	a[7][5] = a[7][4]
	a[2][6] = a[2][7]
	a[5][7] = a[5][8]
	a[8][8] = a[8][7]
	for i in a:
		print(*i, sep='')


def solve():
	z = [0, 2, 3, 4, 5, 6, 7, 8, 9, 1]
	s = [list(input()) for i in range(9)]
	c = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for n in c:
		x = s[n[0]][n[1]]
		s[n[0]][n[1]] = str(z[int(x)])
	s = [''.join(x) for x in s]
	return '\n'.join(s)
[print(solve()) for i in range(int(input()))]


def main():
	test = int(input())
	for t in range(test):
		j = 0
		for i in range(9):
			s = list(input())
			if j >= 9:
				j = int(i / 3)
			if j < 8:
				s[j] = s[j + 1]
			else:
				s[j] = s[0]
			print(''.join(s))
			j += 3
main()


T = int(input())
for t in range(T):
	c = [0, 4, 8, 6, 1, 5, 3, 7, 2]
	a = []
	for i in range(9):
		a.append(list(input()))
		a[i][c[i]] = str(int(a[i][c[i]]) % 9 + 1)
	for i in range(9):
		print(''.join(a[i]))


t = int(input())
for _ in range(t):
	a = []
	for i in range(9):
		a.append(list(map(int, list(input()))))
	for i in range(9):
		s = i % 3 * 3 + i // 3
		if a[i][s] == 9:
			a[i][s] = 1
		else:
			a[i][s] += 1
	for j in a:
		print(''.join(list(map(str, j))))


from sys import stdin
from collections import Counter
input = stdin.readline
for _ in range(int(input())):
	d = []
	for i in range(9):
		d.append([int(x) for x in input().strip()])
	for i in range(3):
		for j in range(3):
			d[i * 3 + j][i + 3 * j] += 1
			if d[i * 3 + j][i + 3 * j] == 10:
				d[i * 3 + j][i + 3 * j] = 1
	for i in range(9):
		print(''.join([str(x) for x in d[i]]))


import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__

def go():
	a = [input() for _ in range(9)]
	return '\n'.join([aa.replace('1', '2') for aa in a])
t = int(input())
ans = []
for _ in range(t):
	ans.append(str(go()))
print('\n'.join(ans))


for _ in range(int(input())):
	a = [list(input().strip()) for index in range(9)]
	a[0][0] = int((int(a[0][0]) + 1) % 9 + (int(a[0][0]) == 8))
	a[1][3] = int((int(a[1][3]) + 1) % 9 + (int(a[1][3]) == 8))
	a[2][6] = int((int(a[2][6]) + 1) % 9 + (int(a[2][6]) == 8))
	a[3][1] = int((int(a[3][1]) + 1) % 9 + (int(a[3][1]) == 8))
	a[4][4] = int((int(a[4][4]) + 1) % 9 + (int(a[4][4]) == 8))
	a[5][7] = int((int(a[5][7]) + 1) % 9 + (int(a[5][7]) == 8))
	a[6][2] = int((int(a[6][2]) + 1) % 9 + (int(a[6][2]) == 8))
	a[7][5] = int((int(a[7][5]) + 1) % 9 + (int(a[7][5]) == 8))
	a[8][8] = int((int(a[8][8]) + 1) % 9 + (int(a[8][8]) == 8))
	for i in range(9):
		print(*a[i], sep='')


def solve():
	li = []
	for i in range(9):
		string = input()
		li.append(string)
	k = 0
	j = 0
	for i in range(3):
		string1 = li[k]
		new1 = string1[0:j] + string1[j] + string1[j] + string1[j + 2:]
		li[k] = new1
		string2 = li[k + 3]
		new2 = string2[0:j] + string2[j + 1] + string2[j + 1] + string2[j + 2:]
		li[k + 3] = new2
		string3 = li[k + 6]
		new3 = string3[0:j + 1] + string3[j + 1] + string3[j + 1] + string3[j + 3:]
		li[k + 6] = new3
		k += 1
		j += 3
	for ele in li:
		print(ele)
t = int(input())
for i in range(t):
	solve()


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
	if space:
		_input = lambda : input().split()
	else:
		_input = lambda : input()
	_list = lambda : list(map(_type, _input()))
	if padding:
		offset = 1
	else:
		offset = 0
	grid = list2d(H + offset * 2, W + offset * 2, intv)
	for i in range(offset, H + offset):
		row = _list()
		for j in range(offset, W + offset):
			grid[i][j] = row[j - offset]
	return grid
for _ in range(INT()):
	grid = build_grid(9, 9, '', str, space=False)
	for i in range(3):
		for j in range(3):
			h = i * 3 + j
			w = j * 3 + i
			grid[h][w] = str(int(grid[h][w]) % 9 + 1)
	for i in range(9):
		print(''.join(grid[i]))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys
from copy import deepcopy

def main():
	t = int(input())
	for _ in range(t):
		Map = [None] * 9
		for i in range(9):
			n = int(input())
			Map[i] = [int(x) for x in list(str(n))]
		Ans = deepcopy(Map)
		for i in range(9):
			for j in range(9):
				if Map[i][j] == 2:
					Ans[i][j] = 1
		for ans in Ans:
			sys.stdout.write(''.join(map(str, ans)) + '\n')
main()


for _ in range(int(input())):
	l = []
	for i in range(9):
		s = input()
		d = s.replace('2', '1')
		l.append(d)
	for i in l:
		print(i)


t = int(input())
for _ in range(t):
	ans = []
	for i in range(9):
		temp = list(input())
		ans.append(temp)
	temp1 = 2
	temp2 = 5
	temp3 = 8
	i = 0
	k = 0
	res = []
	for i in range(3):
		str1 = ans[k]
		str2 = ans[k + 1]
		str3 = ans[k + 2]
		if ord(str1[temp1]) - 48 + 1 > 9:
			str1[temp1] = 1
		else:
			str1[temp1] = ord(str1[temp1]) - 48 + 1
		if ord(str2[temp2]) - 48 + 1 > 9:
			str2[temp2] = 1
		else:
			str2[temp2] = ord(str2[temp2]) - 48 + 1
		if ord(str3[temp3]) - 48 + 1 > 9:
			str3[temp3] = 1
		else:
			str3[temp3] = ord(str3[temp3]) - 48 + 1
		listToStr = ''.join([str(elem) for elem in str1])
		listToStr1 = ''.join([str(elem) for elem in str2])
		listToStr2 = ''.join([str(elem) for elem in str3])
		res.append(listToStr)
		res.append(listToStr1)
		res.append(listToStr2)
		temp1 -= 1
		temp2 -= 1
		temp3 -= 1
		k += 3
	for i in range(9):
		print(res[i])


t = int(input())
for _ in range(t):
	m = []
	for i in range(9):
		s = input().strip()
		s = s.replace('1', '2')
		print(s)


testcases = int(input())
for _ in range(testcases):
	changes = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for i in range(9):
		temp = list(input())
		(i, j) = changes[i]
		x = int(temp[j]) + 1
		if x > 9:
			x = 1
		temp[j] = x
		print(''.join([str(val) for val in temp]))


from sys import stdin, stdout
import traceback
import math
import bisect
from typing import List, Tuple
import itertools as it
from collections import Counter
read = lambda : stdin.readline().strip()
write = stdout.write
writeln = lambda x: write(str(x) + '\n')

def reads(typ=int):
	return list(map(typ, read().split()))

def enumerate_sorted(iterable):
	return sorted(zip(it.count(), iterable), key=lambda x: x[1])

class Sol:

	def __init__(self, mx):
		self.mx = mx

	@classmethod
	def input(cls):
		mx = [[int(c) for c in read()] for _ in range(9)]
		return cls(mx)

	def solve(self):
		self.incr(0, 0)
		self.incr(1, 3)
		self.incr(2, 6)
		self.incr(3, 1)
		self.incr(4, 4)
		self.incr(5, 7)
		self.incr(6, 2)
		self.incr(7, 5)
		self.incr(8, 8)
		for row in self.mx:
			writeln(''.join((str(i) for i in row)))

	def incr(self, i, j):
		tmp = self.mx[i][j]
		tmp += 1
		if tmp == 10:
			tmp = 1
		self.mx[i][j] = tmp

def mytest():
	pass

def main():
	try:
		t = int(read())
		for _ in range(t):
			res = Sol.input().solve()
	except Exception as e:
		print('Got exception:', repr(e))
		print(traceback.format_exc())
main()


t = int(input())
for tt in range(0, t):
	val = []
	for i in range(0, 9):
		s = [int(i) for i in input()]
		val.append(s)
	count = 0
	array = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	while count < 9:
		if val[count][array[count]] != 9:
			val[count][array[count]] = val[count][array[count]] + 1
		else:
			val[count][array[count]] = val[count][array[count]] - 1
		count += 1
	for i in range(0, 9):
		for j in range(0, 9):
			print(val[i][j], end='')
		print()


t = int(input())
for i in range(t):
	for k in range(9):
		s = list(input())
		for j in range(9):
			if int(s[j]) == 1:
				s[j] = '2'
				print(''.join(s))


n = int(input())
arr = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
for _ in range(n):
	for i in range(9):
		line = input()
		ans = ''
		for j in range(9):
			c = int(line[j])
			if (i, j) not in arr:
				ans += str(c)
				continue
			c += 1
			if c > 9:
				c = 1
			ans += str(c)
		ans += '\n'
		print(ans)


tests = int(input())
for t in range(tests):
	l = [[int(i) for i in input()] for j in range(9)]
	tc = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for (i, j) in tc:
		l[i][j] = l[i][j] + 1 if l[i][j] < 9 else 1
	for i in l:
		print(*i, sep='')


t = int(input())
for i in range(0, t):
	A = [[] for j in range(0, 9)]
	for j in range(0, 9):
		s = input()
		for k in range(0, 9):
			A[j].append(s[k])
	change = []
	for j in range(0, 9):
		for k in range(0, 9):
			if A[j][k] == '1':
				if j % 3 == 2:
					change.append([j - 2, k])
				else:
					change.append([j + 1, k])
	for c in change:
		(j, k) = c
		A[j][k] = '1'
	for j in range(0, 9):
		x = ''.join(A[j])
		print(x)


t = int(input())
for i in range(t):
	sp = [0] * 9
	for j in range(9):
		s = input()
		sp[j] = [0] * 9
		for x in range(9):
			sp[j][x] = int(s[x])
	for j in range(3):
		for x in range(3):
			g = sp[3 * x + j][j * 3 + x]
			g += 1
			if g == 10:
				g = 1
			sp[3 * x + j][j * 3 + x] = g
	for j in sp:
		for x in j:
			print(x, end='')
		print()


t = int(input())
for test in range(t):
	sud = []
	for i in range(1, 10):
		sud.append([int(x) for x in input()])
	if sud[0][0] == 1:
		sud[0][0] = 2
	else:
		sud[0][0] = 1
	if sud[1][4] == 1:
		sud[1][4] = 2
	else:
		sud[1][4] = 1
	if sud[2][8] == 1:
		sud[2][8] = 2
	else:
		sud[2][8] = 1
	if sud[3][1] == 1:
		sud[3][1] = 2
	else:
		sud[3][1] = 1
	if sud[4][5] == 1:
		sud[4][5] = 2
	else:
		sud[4][5] = 1
	if sud[5][6] == 1:
		sud[5][6] = 2
	else:
		sud[5][6] = 1
	if sud[6][2] == 1:
		sud[6][2] = 2
	else:
		sud[6][2] = 1
	if sud[7][3] == 1:
		sud[7][3] = 2
	else:
		sud[7][3] = 1
	if sud[8][7] == 1:
		sud[8][7] = 2
	else:
		sud[8][7] = 1
	print()
	for i in range(9):
		for j in range(9):
			print(sud[i][j], end='')
		print()


t = int(input())
for _ in range(t):
	idx = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		a = list(map(int, input()))
		a[idx[i]] = a[idx[i]] + 1
		if a[idx[i]] > 9:
			a[idx[i]] = 1
		print(''.join(map(str, a)))


for x in range(int(input())):
	sud = []
	for i in range(9):
		z = input()
		s = ''
		for j in z:
			if j == '1':
				s += '2'
			else:
				s += j
		sud += [s]
	for i in sud:
		print(i)


t = int(input())
for tt in range(t):
	arr = []
	for i in range(9):
		s = input().strip()
		l = []
		for i1 in s:
			l.append(int(i1))
		arr.append(l)
	arr[0][1] = arr[0][0]
	arr[1][4] = arr[1][3]
	arr[2][7] = arr[2][6]
	arr[3][0] = arr[3][1]
	arr[4][3] = arr[4][4]
	arr[5][6] = arr[5][7]
	arr[6][2] = arr[6][1]
	arr[7][5] = arr[7][4]
	arr[8][8] = arr[8][7]
	print()
	for i in range(9):
		for j in range(9):
			print(arr[i][j], end='')
		print()


for t in range(int(input())):
	n = 9
	l = []
	while n > 0:
		s = input()
		s = list(s)
		l.append(s)
		n = n - 1
	for i in range(len(l)):
		for j in range(9):
			if l[i][j] == '1':
				l[i][j] = '9'
	g = []
	for b in range(len(l)):
		h = l[b]
		p = ''.join(h)
		g.append(p)
	print(*g, sep='\n')


import sys
input = sys.stdin.readline
import heapq
import copy
import math

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

class Node:

	def _init_(self, val):
		self.data = val
		self.left = None
		self.right = None

class fen_tree:

	def __init__(self, list):
		self.array = [0] + list
		for idx in range(1, len(self.array)):
			idx2 = idx + (idx & -idx)
			if idx2 < len(self.array):
				self.array[idx2] += self.array[idx]

	def prefix_query(self, idx):
		result = 0
		while idx:
			result += self.array[idx]
			idx -= idx & -idx
		return result

	def prints(self):
		print(self.array)
		return

	def range_query(self, from_idx, to_idx):
		return self.prefix_query(to_idx) - self.prefix_query(from_idx - 1)

	def update(self, idx, add):
		while idx < len(self.array):
			self.array[idx] += add
			idx += idx & -idx

def pre_sum(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def pre_back(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def search_leftmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[l] == val:
			return l
		if r - l <= 1:
			if arr[r] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] >= val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def search_rightmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[r] == val:
			return r
		if r - l <= 1:
			if arr[l] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] > val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	for test in range(tests):
		s = [[] for i in range(9)]
		for i in range(9):
			s[i] = insr()
		change = [[0, 0], [1, 7], [2, 5], [3, 6], [4, 4], [5, 1], [6, 2], [7, 8], [8, 3]]
		for i in change:
			s[i[0]][i[1]] = str((int(s[i[0]][i[1]]) - 2 + 9) % 9 + 1)
		for i in range(9):
			s[i] = ''.join(s[i])
			print(s[i])
main()


t = int(input())
while t > 0:
	t -= 1
	A = []
	for i in range(9):
		s = input()
		temp = []
		for j in range(9):
			temp.append(int(s[j]))
		A.append(temp)
	for i in range(9):
		if 0 <= i <= 2:
			j = 3 * (i % 3)
		elif 3 <= i <= 5:
			j = 3 * (i % 3) + 1
		else:
			j = 3 * (i % 3) + 2
		if A[i][j] == 5:
			A[i][j] = 6
		else:
			A[i][j] = 10 - A[i][j]
	for i in range(9):
		for j in range(9):
			print(A[i][j], end='')
		print()


def main():
	T = int(input())
	for _ in range(T):
		arr = []
		for _ in range(9):
			arr.append(list(input()))
		k = 0
		for i in range(0, 9, 3):
			arr[i][k] = arr[i + 1][k]
			arr[i + 1][k + 3] = arr[i + 2][k + 3]
			arr[i + 2][k + 6] = arr[i + 1][k + 6]
			k += 1
		for i in range(9):
			print(''.join(arr[i]))
main()


a = int(input())
answer = ''
for x in range(a):
	for y in range(9):
		line = str(input())
		index = y % 3 * 3 + y // 3
		answer = line[:index] + line[index - 1]
		if index < 8:
			answer += line[index + 1:]
		print(answer)


def antiSudoku(string_arr):
	for i in range(9):
		string = string_arr[i]
		string = string.replace('2', '1')
		print(string)
t = int(input())
for _ in range(t):
	string_arr = []
	for i in range(9):
		string_arr.append(input())
	antiSudoku(string_arr)


def main():
	t = int(input())
	for _ in range(t):
		lines = []
		for _ in range(9):
			l = input()
			lines.append([])
			for c in l:
				lines[-1].append(int(c))
		indices = (0, 3, 6, 1, 4, 7, 2, 5, 8)
		for (i, j) in enumerate(indices):
			lines[i][j] = (lines[i][j] + 1) % 9 + 1
		for l in lines:
			print(''.join((str(j) for j in l)))
main()


t = int(input())
for x in range(t):
	for y in range(9):
		a = input()
		if (3 * y + 1 + y // 3) % 9 != 0:
			if a[(3 * y + 1 + y // 3) % 9 - 1] != '9':
				a = a[:(3 * y + 1 + y // 3) % 9 - 1] + str(int(a[(3 * y + 1 + y // 3) % 9 - 1]) + 1) + a[(3 * y + 1 + y // 3) % 9:]
			else:
				a = a[:(3 * y + 1 + y // 3) % 9 - 1] + '1' + a[(3 * y + 1 + y // 3) % 9:]
		elif a[(3 * y + 1 + y // 3) % 9 - 1] != '9':
			a = a[:(3 * y + 1 + y // 3) % 9 - 1] + str(int(a[(3 * y + 1 + y // 3) % 9 - 1]) + 1)
		else:
			a = a[:(3 * y + 1 + y // 3) % 9 - 1] + '1'
		print(a)


t = int(input())
for i in range(t):
	x = 9
	ii = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for j in range(9):
		s = input()
		s1 = list(s)
		s1[ii[j]] = str((int(s1[ii[j]]) + 1) % 9)
		if s1[ii[j]] == '0':
			s1[ii[j]] = '9'
		print(''.join(s1))


import random, math
from copy import deepcopy as dc

def solution(sud):
	sud[0][0] = sud[0][1] + 1 - 1
	sud[1][3] = sud[1][4] + 1 - 1
	sud[2][6] = sud[2][7] + 1 - 1
	sud[3][1] = sud[3][2] + 1 - 1
	sud[4][4] = sud[4][5] + 1 - 1
	sud[5][7] = sud[5][8] + 1 - 1
	sud[6][2] = sud[6][1] + 1 - 1
	sud[7][5] = sud[7][4] + 1 - 1
	sud[8][8] = sud[8][7] + 1 - 1
	return sud

def input_test():
	for _ in range(int(input())):
		sud = []
		for i in range(9):
			li = list(map(int, list(str(input()))))
			sud.append(li)
		out = solution(sud)
		for i in out:
			print(''.join(list(map(str, i))))
input_test()


for tc in range(int(input())):
	A = [[], [], [], [], [], [], [], [], []]
	for i in range(9):
		for j in input():
			A[i].append(int(j))
	A[0][0] = A[0][1]
	A[1][3] = A[1][4]
	A[2][6] = A[2][7]
	A[3][1] = A[3][2]
	A[4][4] = A[4][5]
	A[5][7] = A[5][8]
	A[6][2] = A[6][3]
	A[7][5] = A[7][6]
	A[8][8] = A[8][0]
	for i in range(9):
		for j in range(9):
			print(A[i][j], end='')
		print()


t = int(input())
keys = [i for i in range(9)]
val = [2, 5, 8, 1, 4, 7, 3, 6, 9]
d = dict(zip(keys, val))
for _ in range(t):
	A = []
	for i in range(9):
		s = input()
		l = list(s)
		if l[d[i] - 1] != '1':
			l[d[i] - 1] = '1'
		else:
			l[d[i] - 1] = '2'
		A.append(l)
	for i in range(9):
		print(''.join(A[i]))


for _ in range(int(input())):
	sudoku2 = []
	for i in range(9):
		sudoku2.append(list(input()))
	indexes = []
	col_done = []
	row_done = []
	for no in '123456789':
		sudoku = sudoku2[:]
		changes = 0
		for ver_block in range(3):
			for hor_block in range(3):
				one_added = False
				for row_no in range(3 * ver_block, 3 * (ver_block + 1)):
					if one_added:
						break
					if row_no in row_done:
						continue
					for col_no in range(3 * hor_block, 3 * (hor_block + 1)):
						if col_no in col_done:
							continue
						if sudoku[row_no][col_no] == no:
							continue
						sudoku[row_no][col_no] = no
						col_done.append(col_no)
						row_done.append(row_no)
						one_added = True
						changes += 1
						break
			if changes == 9:
				break
	for i in range(9):
		print(''.join(sudoku[i]))


t = int(input())
while t > 0:
	a = list()
	for i in range(0, 9):
		a.append(input())
		a[i] = a[i].replace('1', '2')
	for i in range(0, 9):
		print(a[i])
	t -= 1


for i in range(int(input())):
	for j in range(9):
		row = list(input())
		for k in range(len(row)):
			if row[k] == '3':
				row[k] = '2'
		print(''.join(row))


def array_to_string(a):
	s = ''
	for i in a:
		s += str(i)
	return s
t = int(input())
while t > 0:
	t = t - 1
	mat = []
	for i in range(9):
		mat.append([int(i) for i in input()])
	temp = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for i in temp:
		row = i[0]
		col = i[1]
		if mat[row][col] == 9:
			mat[row][col] = 1
		else:
			mat[row][col] += 1
	for i in range(9):
		for j in range(9):
			print(mat[i][j], end='')
		print()


t = int(input(''))
for _ in range(t):
	ans = []
	for i in range(9):
		a = input('')
		s = ''
		for i in range(9):
			if a[i] != '9':
				s = s + a[i]
			else:
				s = s + '1'
		ans.append(s)
	for i in range(9):
		print(ans[i])


tc = int(input())
for _ in range(tc):
	L = [list(map(int, list(input()))) for i in range(9)]
	D = [[0, 0], [3, 1], [6, 2], [1, 3], [4, 4], [7, 5], [2, 6], [5, 7], [8, 8]]
	for i in D:
		Y = i[0]
		X = i[1]
		L[Y][X] = L[Y][X] + 1
		if L[Y][X] == 10:
			L[Y][X] = 1
	for s in L:
		for x in s:
			print(x, end='')
		print()


def interize(ln):
	for i in range(len(ln)):
		ln[i] = int(ln[i])
	return ln

def solve(block):
	pairs = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for i in range(9):
		block[pairs[i][0]][pairs[i][1]] = block[pairs[i][0]][pairs[i][1]] % 9 + 1
	for i in range(9):
		for j in range(9):
			block[i][j] = str(block[i][j])
	for i in range(9):
		print(''.join(block[i]))
t = int(input())
for i in range(t):
	block = []
	for j in range(9):
		ln = [x for x in input()]
		block.append(interize(ln))
	solve(block)


t = int(input())
for i in range(t):
	l = []
	for j in range(9):
		l.append(input())
	c = -1
	for j in range(9):
		if j % 3 == 0:
			c += 1
			c = c % 9
		if j == 8:
			l[j] = l[j][:c] + l[j][c - 1] + l[j][c + 1:]
			break
		l[j] = l[j][:c] + l[j][c + 1] + l[j][c + 1:]
		c += 3
		c = c % 9
	for j in range(9):
		print(l[j])


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		s = []
		for i in range(9):
			n = input()
			s.append(str(n))
		ans = []
		t = ''
		for i in range(9):
			t = ''
			for j in range(9):
				if s[i][j] == '1':
					t += '2'
				else:
					t += s[i][j]
			ans.append(t)
		for i in range(9):
			print(ans[i])


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

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

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
poss = [[0, 0], [3, 1], [6, 2], [1, 3], [4, 4], [7, 5], [2, 6], [5, 7], [8, 8]]
for _ in range(val()):
	l = []
	for i in range(9):
		l.append(li3())
	for (i, j) in poss:
		l[i][j] = 10 - l[i][j] if l[i][j] != 5 else 6
	for i in range(9):
		print(*l[i], sep='')


import sys

def I():
	return sys.stdin.readline().rstrip()
for _ in range(int(I())):
	t = [[c for c in I()] for ro in range(9)]
	l = sorted([(t[i][i], i) for i in range(9)])
	for i in range(3):
		for j in range(3):
			(ii, jj) = (i * 3 + j, j * 3 + i)
			t[ii][jj] = chr(ord('1') + ord(t[ii][jj]) % 9)
	for ro in t:
		print(''.join(ro))


t = int(input())
a = [[0 for i in range(9)] for _ in range(9)]
for i in range(t):
	for k in range(0, 9):
		s = input()
		for j in range(0, 9):
			a[k][j] = s[j]
	newmean = '1'
	for k in range(0, 3):
		i = k
		j = 3 * k
		for _ in range(0, 3):
			if a[i][j] == newmean:
				a[i][j] = '2'
			elif a[i][j] != newmean:
				a[i][j] = newmean
			i += 3
			j += 1
	for i in range(0, 9):
		for j in range(0, 9):
			print(a[i][j], end='')
		print()


for _ in range(int(input())):
	sudoku = []
	for _ in range(9):
		sudoku.append([int(i) for i in input().strip()])
	pos1 = [[0, 0], [1, 4], [2, 8]]
	pos2 = [[3, 1], [4, 5], [5, 6]]
	pos3 = [[6, 2], [7, 3], [8, 7]]
	val_pos1 = [sudoku[x][y] for [x, y] in pos1]
	val_pos2 = [sudoku[x][y] for [x, y] in pos2]
	val_pos3 = [sudoku[x][y] for [x, y] in pos3]
	for i in range(9):
		if i not in val_pos1:
			for [x, y] in pos1:
				sudoku[x][y] = sudoku[x][y + (1 if y != 8 else -1)]
			break
	for i in range(9):
		if i not in val_pos2:
			for [x, y] in pos2:
				sudoku[x][y] = sudoku[x][y + (1 if y != 5 else -1)]
			break
	for i in range(9):
		if i not in val_pos3:
			for [x, y] in pos3:
				sudoku[x][y] = sudoku[x][y + (1 if y != 2 else -1)]
			break
	for x in sudoku:
		print(''.join([str(y) for y in x]))


for _ in range(int(input())):
	for r in range(9):
		print(input().replace('5', '1'))


T = int(input())
out = []
for i in range(T):
	out_1 = []
	for j in range(9):
		out_1.append(list(input()))
	for j in range(9):
		for k in range(9):
			if out_1[j][k] == '2':
				out_1[j][k] = '1'
	for j in range(9):
		out.append(int(''.join(out_1[j])))
for i in range(9 * T):
	print(out[i])


def compute(sudoku):
	oper = [[0, 0], [1, 4], [2, 8], [3, 1], [4, 3], [5, 7], [6, 2], [7, 5], [8, 6]]
	for i in range(9):
		(i, j) = oper[i]
		if j == 8:
			sudoku[i][j] = sudoku[i][j - 1]
		else:
			sudoku[i][j] = sudoku[i][j + 1]
	for i in range(9):
		for j in range(9):
			print(sudoku[i][j], end='')
		print()
t = int(input())
for _ in range(t):
	sudoku = []
	for _ in range(9):
		n = str(input())
		sudoku.append(list(n))
	compute(sudoku)


import math
from collections import Counter
for _ in range(int(input())):
	l = []
	for i in range(9):
		l.append(input().split())
	for i in l:
		print(i[0].replace('1', '9'))


def givalt(ch):
	if int(ch) + 1 < 9:
		return str(int(ch) + 1)
	return str(1)

def help():
	inp = input()
	changed = givalt(inp[0]) + inp[1:]
	print(changed)
	inp = input()
	changed = inp[:3] + givalt(inp[3]) + inp[3 + 1:]
	print(changed)
	inp = input()
	changed = inp[:6] + givalt(inp[6]) + inp[6 + 1:]
	print(changed)
	inp = input()
	changed = inp[:1] + givalt(inp[1]) + inp[1 + 1:]
	print(changed)
	inp = input()
	changed = inp[:4] + givalt(inp[4]) + inp[4 + 1:]
	print(changed)
	inp = input()
	changed = inp[:7] + givalt(inp[7]) + inp[7 + 1:]
	print(changed)
	inp = input()
	changed = inp[:2] + givalt(inp[2]) + inp[2 + 1:]
	print(changed)
	inp = input()
	changed = inp[:5] + givalt(inp[5]) + inp[5 + 1:]
	print(changed)
	inp = input()
	changed = inp[:8] + givalt(inp[8])
	print(changed)
for qw in range(int(input())):
	help()


for _ in range(int(input())):
	for i in range(9):
		ls = list(input())
		s = ''
		for j in range(9):
			if ls[j] == '9':
				ls[j] = '1'
				s += ls[j]
			else:
				s += ls[j]
		print(s)


for _ in range(int(input())):
	board = []
	for _ in range(9):
		arr = input()
		arr_ = [i for i in arr]
		board.append(arr_)
	board[0][0] = chr((ord(board[0][0]) + 1 - 48) % 10 + 48)
	board[1][3] = chr((ord(board[1][3]) + 1 - 48) % 10 + 48)
	board[2][6] = chr((ord(board[2][6]) + 1 - 48) % 10 + 48)
	board[3][1] = chr((ord(board[3][1]) + 1 - 48) % 10 + 48)
	board[4][4] = chr((ord(board[4][4]) + 1 - 48) % 10 + 48)
	board[5][7] = chr((ord(board[5][7]) + 1 - 48) % 10 + 48)
	board[6][2] = chr((ord(board[6][2]) + 1 - 48) % 10 + 48)
	board[7][5] = chr((ord(board[7][5]) + 1 - 48) % 10 + 48)
	board[8][8] = chr((ord(board[8][8]) + 1 - 48) % 10 + 48)
	for i in range(9):
		for j in range(9):
			if board[i][j] == '0':
				print('1', end='')
			else:
				print(board[i][j], end='')
		print()


numcases = int(input())

def solve():
	sudoku = []
	for i in range(9):
		row = []
		placeholder = str(input().split())
		for j in range(9):
			row.append(placeholder[j + 2])
		sudoku.append(row)
	column = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		if int(sudoku[i][column[i]]) == 2:
			sudoku[i][column[i]] = 3
		else:
			sudoku[i][column[i]] = 2
	for i in range(9):
		print(*sudoku[i], sep='')
for n in range(numcases):
	solve()


import sys
T = int(input())
GX = [0, 1, 2, 3, 4, 5, 6, 7, 8]
GY = [0, 3, 6, 1, 4, 7, 2, 5, 8]
while T:
	X = [[0 for i in range(9)] for j in range(9)]
	for r in range(9):
		s = input()
		for c in range(9):
			X[r][c] = int(s[c])
	for m in range(9):
		i = GX[m]
		j = GY[m]
		if X[i][j] != 9:
			X[i][j] = 9
		else:
			X[i][j] = 8
	for x in X:
		for y in x:
			print(y, end='')
		print()
	T = T - 1


t = int(input())
while t:
	a = [[] for i in range(0, 9)]
	for i in range(0, 9):
		a[i] = list(input())
		for j in range(0, 9):
			if a[i][j] == '2':
				a[i][j] = 1
	for i in range(0, 9):
		for j in range(0, 9):
			print(a[i][j], end='')
		print()
	t = t - 1


def f(c):
	if int(c) == 9:
		return '1'
	else:
		return chr(ord(c) + 1)

def solve():
	m = []
	for i in range(0, 9):
		s = input()
		m.append(list(s))
	m[0][0] = f(m[0][0])
	m[1][3] = f(m[1][3])
	m[2][6] = f(m[2][6])
	m[3][1] = f(m[3][1])
	m[4][4] = f(m[4][4])
	m[5][7] = f(m[5][7])
	m[6][2] = f(m[6][2])
	m[7][5] = f(m[7][5])
	m[8][8] = f(m[8][8])
	for i in range(0, 9):
		print(''.join(m[i]))

def main():
	t = int(input())
	for i in range(0, t):
		solve()
main()


import sys
import math
from collections import defaultdict

def solve():
	sudoku = []
	for i in range(9):
		row = list(input())
		sudoku.append(row)
	j = 10
	count = 0
	for i in range(9):
		if j > 8:
			j = count
			count += 1
		n = int(sudoku[i][j])
		n = n + 1 if n != 9 else 1
		sudoku[i][j] = str(n)
		j += 3
	for i in range(9):
		print(''.join(sudoku[i]))
test_cases = int(input())
for _ in range(test_cases):
	solve()


t = int(input())
while t:
	t -= 1
	for i in range(9):
		s = list(input())
		for i in range(9):
			if s[i] == '2':
				s[i] = '3'
		for i in range(9):
			print(s[i], end='')
		print()


c = int(input())
for i in range(c):
	sudo = []
	for j in range(9):
		sudo.append(str(input()))
	for row in sudo:
		row = row.replace('2', '1')
		print(row)


import sys
import math
from collections import Counter
debug = 1
readln = sys.stdin.readline

def readint():
	return int(readln().strip())

def readints():
	return map(int, readln().split())

def readstr():
	return readln().strip()

def readstrs():
	return readln().split()

def dbg(*args):
	if debug:
		print(' '.join(map(str, args)))

def change(G, r, c):
	if r % 3 == 0:
		G[r][c] = G[r + 1][c]
	else:
		G[r][c] = G[r - 1][c]

def solve(G):
	change(G, 0, 0)
	change(G, 1, 3)
	change(G, 2, 6)
	change(G, 3, 1)
	change(G, 4, 4)
	change(G, 5, 7)
	change(G, 6, 2)
	change(G, 7, 5)
	change(G, 8, 8)
t = readint()
for _ in range(t):
	G = []
	for _ in range(9):
		G.append(list(readstr()))
	solve(G)
	for i in range(9):
		print(''.join(G[i]))


def anti_sudoku():
	for i in range(3):
		s = input()
		if s[3 * i] == '1':
			print(s[:3 * i] + '2' + s[3 * i + 1:])
		else:
			print(s[:3 * i] + '1' + s[3 * i + 1:])
	for i in range(3):
		s = input()
		if s[3 * i + 1] == '1':
			print(s[:3 * i + 1] + '2' + s[3 * i + 2:])
		else:
			print(s[:3 * i + 1] + '1' + s[3 * i + 2:])
	for i in range(3):
		s = input()
		if s[3 * i + 2] == '1':
			print(s[:3 * i + 2] + '2' + s[3 * i + 3:])
		else:
			print(s[:3 * i + 2] + '1' + s[3 * i + 3:])
t = int(input())
for i in range(t):
	anti_sudoku()


for _ in range(int(input())):
	a = []
	for i in range(9):
		s = input()
		a.append(s)
	for i in range(9):
		for j in range(9):
			if i == 0 and j == 0:
				if a[i][j] != '1':
					a[i] = a[i].replace(a[i][j], '1')
				else:
					a[i] = a[i].replace(a[i][j], '2')
			elif i == 1 and j == 3:
				if a[i][j] != '1':
					a[i] = a[i].replace(a[i][j], '1')
				else:
					a[i] = a[i].replace(a[i][j], '2')
			elif i == 2 and j == 6:
				if a[i][j] != '1':
					a[i] = a[i].replace(a[i][j], '1')
				else:
					a[i] = a[i].replace(a[i][j], '2')
			elif i == 3 and j == 1:
				if a[i][j] != '1':
					a[i] = a[i].replace(a[i][j], '1')
				else:
					a[i] = a[i].replace(a[i][j], '2')
			elif i == 4 and j == 4:
				if a[i][j] != '1':
					a[i] = a[i].replace(a[i][j], '1')
				else:
					a[i] = a[i].replace(a[i][j], '2')
			elif i == 5 and j == 7:
				if a[i][j] != '1':
					a[i] = a[i].replace(a[i][j], '1')
				else:
					a[i] = a[i].replace(a[i][j], '2')
			elif i == 6 and j == 2:
				if a[i][j] != '1':
					a[i] = a[i].replace(a[i][j], '1')
				else:
					a[i] = a[i].replace(a[i][j], '2')
			elif i == 7 and j == 5:
				if a[i][j] != '1':
					a[i] = a[i].replace(a[i][j], '1')
				else:
					a[i] = a[i].replace(a[i][j], '2')
			elif i == 8 and j == 8:
				if a[i][j] != '1':
					a[i] = a[i].replace(a[i][j], '1')
				else:
					a[i] = a[i].replace(a[i][j], '2')
			else:
				continue
	for i in range(9):
		print(a[i])


for t in range(int(input())):
	sud = []
	for i in range(9):
		sud.append(list(map(int, input())))
	for i in range(9):
		for j in range(9):
			if sud[i][j] == 2:
				sud[i][j] = 1
	for i in range(9):
		print(*sud[i], sep='')


for xyz in range(0, int(input())):
	l = []
	for i in range(0, 9):
		l.append(input())
	for i in range(0, 9):
		s = ''
		for j in range(0, 9):
			if l[i][j] == '9':
				s += l[i][0:j]
				s += '8'
				s += l[i][j + 1:]
		print(s)


t = int(input())
while t:
	l = []
	for i in range(9):
		s = input()
		l.append(s)
	ans = []
	temp = l[0][1] + l[0][1:]
	ans.append(temp)
	temp = l[1][:3] + l[1][4] + l[1][4:]
	ans.append(temp)
	temp = l[2][:6] + l[2][7] + l[2][7:]
	ans.append(temp)
	temp = l[3][:1] + l[3][2] + l[3][2:]
	ans.append(temp)
	temp = l[4][:4] + l[4][5] + l[4][5:]
	ans.append(temp)
	temp = l[5][:7] + l[5][8] + l[5][8:]
	ans.append(temp)
	temp = l[6][:8] + l[6][7]
	ans.append(temp)
	temp = l[7][:5] + l[7][6] + l[7][6:]
	ans.append(temp)
	temp = l[8][:2] + l[8][3] + l[8][3:]
	ans.append(temp)
	print('\n')
	for i in ans:
		print(i)
	t -= 1


t = int(input())
for _ in range(t):
	mat = []
	for __ in range(9):
		ar = [x for x in input()]
		mat.append(ar)
	ch = [(1, 1), (2, 4), (3, 7), (4, 2), (5, 5), (6, 8), (7, 3), (8, 6), (9, 9)]
	for tup in ch:
		a = tup[0] - 1
		b = tup[1] - 1
		if mat[a][b] == '9':
			mat[a][b] = '1'
		else:
			ori = int(mat[a][b])
			mat[a][b] = str(ori + 1)
	for row in mat:
		for val in row:
			print(val, end='')
		print()


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	for _ in range(int(input())):
		so = []
		for i in range(9):
			so.append(list(input().strip()))
		for i in range(3):
			for j in range(3):
				ti = i * 3 + j
				tj = i + 3 * j
				so[ti][tj] = str(int(so[ti][tj]) % 9 + 1)
		for i in so:
			print(''.join(i))
main()


t = int(input())
while t:
	t += -1
	sud = []
	for i in range(9):
		s = input()
		tmp = []
		for i in s:
			tmp.append(i)
		sud.append(tmp)
	if sud[0][0] == '1':
		sud[0][0] = '2'
	else:
		sud[0][0] = '1'
	if sud[1][3] == '1':
		sud[1][3] = '2'
	else:
		sud[1][3] = '1'
	if sud[2][6] == '1':
		sud[2][6] = '2'
	else:
		sud[2][6] = '1'
	if sud[3][1] == '1':
		sud[3][1] = '2'
	else:
		sud[3][1] = '1'
	if sud[4][4] == '1':
		sud[4][4] = '2'
	else:
		sud[4][4] = '1'
	if sud[5][7] == '1':
		sud[5][7] = '2'
	else:
		sud[5][7] = '1'
	if sud[6][2] == '1':
		sud[6][2] = '2'
	else:
		sud[6][2] = '1'
	if sud[7][5] == '1':
		sud[7][5] = '2'
	else:
		sud[7][5] = '1'
	if sud[8][8] == '1':
		sud[8][8] = '2'
	else:
		sud[8][8] = '1'
	for i in sud:
		print(*i, sep='')


t = int(input())
for turn in range(t):
	ans = [list(str(input())) for i in range(9)]
	num = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		if ans[i][num[i]] == '9':
			ans[i][num[i]] = '1'
		else:
			ans[i][num[i]] = str(int(ans[i][num[i]]) + 1)
	for i in range(9):
		print(''.join(ans[i]))


t = int(input())
sudoku = ['', '', '', '', '', '', '', '', '']
for x in range(t):
	for l in range(9):
		sudoku[l] = input()
	changeSquares = [sudoku[0][0], sudoku[1][3], sudoku[2][6], sudoku[3][1], sudoku[4][4], sudoku[5][7], sudoku[6][2], sudoku[7][5], sudoku[8][8]]
	for c in range(9):
		if changeSquares[c] == '1':
			changeSquares[c] = '2'
		else:
			changeSquares[c] = '1'
	print(changeSquares[0] + sudoku[0][1:])
	print(sudoku[1][:3] + changeSquares[1] + sudoku[1][4:])
	print(sudoku[2][:6] + changeSquares[2] + sudoku[2][7:])
	print(sudoku[3][:1] + changeSquares[3] + sudoku[3][2:])
	print(sudoku[4][:4] + changeSquares[4] + sudoku[4][5:])
	print(sudoku[5][:7] + changeSquares[5] + sudoku[5][8:])
	print(sudoku[6][:2] + changeSquares[6] + sudoku[6][3:])
	print(sudoku[7][:5] + changeSquares[7] + sudoku[7][6:])
	print(sudoku[8][:8] + changeSquares[8])


for _ in range(int(input())):
	for _ in range(9):
		k = input()
		a = k.replace('2', '1')
		print(a)


t = int(input())
for q in range(t):
	matr = []
	for i in range(9):
		x = int(input())
		mas = []
		for j in range(9):
			mas.append(x % 10)
			x //= 10
		mas.reverse()
		matr.append(mas)
	matr[0][0] = matr[1][0]
	matr[3][1] = matr[4][1]
	matr[6][2] = matr[7][2]
	matr[1][3] = matr[2][3]
	matr[4][4] = matr[5][4]
	matr[7][5] = matr[8][5]
	matr[2][6] = matr[3][6]
	matr[5][7] = matr[6][7]
	matr[8][8] = matr[7][8]
	for i in matr:
		for j in i:
			print(j, end='')
		print()


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		sudoku = []
		for i in range(9):
			sudoku.append([int(x) for x in input()])
		answer = []
		indices = ['00', '13', '31', '26', '62', '44', '57', '75', '88']
		for i in range(9):
			for j in range(9):
				if str(i) + str(j) in indices:
					if sudoku[i][j] == 1:
						print(2, end='')
					else:
						print(1, end='')
				else:
					print(sudoku[i][j], end='')
			print()
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


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

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

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	mat = []
	for i in range(9):
		l = insr()
		for i in range(9):
			l[i] = int(l[i])
		mat.append(l)
	for i in range(3):
		for j in range(3):
			mat[i * 3 + j][3 * j + i] = (mat[i * 3 + j][3 * j + i] + 1) % 9 + 1
	for i in range(9):
		ans = ''
		for x in mat[i]:
			ans += str(x)
		print(ans)


t = int(input())
candidate = None
for i in range(t):
	for j in [0, 3, 6, 1, 4, 7, 2, 5, 8]:
		line = list(input())
		line[j] = str(int(line[j]) % 9 + 1)
		print(''.join(line))


t = input()
index = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for _ in range(int(t)):
	a = []
	for i in range(9):
		a.append(input())
		a[i] = list(a[i])
		if a[i][index[i]] == '9':
			a[i][index[i]] = '1'
		else:
			a[i][index[i]] = chr(ord(a[i][index[i]]) + 1)
		a[i] = ''.join(a[i])
		print(a[i])


t = int(input())
while t:
	s = []
	for i in range(9):
		s.append(list(input()))
	for i in range(9):
		for j in range(9):
			if s[i][j] == '9':
				s[i][j] = '1'
	for i in range(9):
		print(''.join(s[i]))
	t = t - 1


from collections import defaultdict
t = int(input())
for i in range(t):
	s = []
	for j in range(9):
		s.append(input())
	s1 = []
	for k in s:
		ans = ''
		for j in k:
			if j == '2':
				ans += '1'
			else:
				ans += j
		s1.append(ans)
	for j in s1:
		print(j)


import sys
t = int(sys.stdin.readline())
k = 1
while k <= t:
	sudoku = []
	i = 0
	while i < 9:
		arr = sys.stdin.readline().strip()
		sudoku.append(list(map(int, arr)))
		i = i + 1
	index_list = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	i = 0
	for ind in index_list:
		val = sudoku[i][ind]
		if val < 5:
			sudoku[i][ind] = val + 1
		else:
			sudoku[i][ind] = val - 1
		i = i + 1
	for l in sudoku:
		output = ''.join(list(map(str, l)))
		print(output)
	k = k + 1


y = int(input())
for i in range(y):
	ans = []
	for j in range(9):
		a = input()
		t = int(j / 3) + 3 * (j % 3)
		if t == 8:
			ans.append(a[:t] + a[t - 1] + a[t + 1:])
			continue
		ans.append(a[:t] + a[t + 1] + a[t + 1:])
	print()
	for k in ans:
		print(k)


t = int(input())
for i in range(t):
	m = []
	for j in range(9):
		l = str(input())
		for k in range(9):
			if l[k] == '5':
				l = l[:k] + '1' + l[k + 1:]
		m.append(l)
	for j in m:
		print(j)


t = int(input())
for x in range(t):
	grid = []
	for y in range(9):
		s = input()
		grid.append(s.replace('4', '5'))
	for z in grid:
		print(z)


for _ in range(int(input())):
	for _ in range(9):
		s = input()
		print(s.replace('4', '1'))


for _ in range(int(input())):
	lst = []
	for i in range(9):
		s = input()
		s = s.replace('1', '2')
		lst.append(s)
	for a in lst:
		print(a)


t = int(input())
for z in range(t):
	l = []
	for i in range(9):
		s = input()
		k = list(s)
		l.append(k)
	for i in range(3):
		if l[i][3 * i] == '1':
			l[i][3 * i] = '2'
		else:
			l[i][3 * i] = '1'
	for i in range(3):
		if l[3 + i][3 * i + 1] == '1':
			l[3 + i][3 * i + 1] = '2'
		else:
			l[3 + i][3 * i + 1] = '1'
	for i in range(3):
		if l[6 + i][3 * i + 2] == '1':
			l[6 + i][3 * i + 2] = '2'
		else:
			l[6 + i][3 * i + 2] = '1'
	for i in range(9):
		print(''.join(l[i]))


t = int(input())
smp = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for _ in range(t):
	g = []
	for j in range(9):
		g.append([int(i) for i in list(input())])
	cur = 0
	for i in smp:
		if g[i][cur] != 1:
			g[i][cur] = 1
			cur += 1
		else:
			g[i][cur] = 2
			cur += 1
	for i in range(9):
		for j in range(9):
			print(g[i][j], end='')
		print()


test = int(input())
i = 1
while i <= test:
	a = []
	for j in range(9):
		n = input()
		a.append(n)
	check = 0
	t = 0
	for j in range(9):
		if t >= 9:
			t = check + 1
			check += 1
		temp = []
		for k in range(9):
			temp.append(a[j][k])
		if temp[t] != '9':
			temp[t] = '9'
			t += 3
		else:
			temp[t] = '8'
			t += 3
		a[j] = ''.join(temp)
	for j in range(9):
		print(a[j])
	i += 1


t = int(input())
for ig in range(t):
	lst1 = list(input())
	lst2 = list(input())
	lst3 = list(input())
	lst4 = list(input())
	lst5 = list(input())
	lst6 = list(input())
	lst7 = list(input())
	lst8 = list(input())
	lst9 = list(input())
	lst = lst1 + lst2 + lst3 + lst4 + lst5 + lst6 + lst7 + lst8 + lst9
	ans = []
	for i in lst:
		ans += [int(i)]
	l = [0, 16, 23, 30, 37, 53, 60, 67, 74]
	for i in l:
		if ans[i] == 9:
			ans[i] = 1
		else:
			ans[i] += 1
	for i in range(len(ans)):
		if i % 9 == 0 and i > 0:
			print()
		print(ans[i], end='')
	print()


import heapq as hp
import collections
import bisect

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int):
	return sorted(map(func, input().split()))

def range_n():
	return range(int(input()))

def counter(a):
	d = {}
	for x in a:
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	return d

def getint():
	return int(input())

def replace(n):
	n = int(n)
	if n == 9:
		n -= 1
	else:
		n += 1
	return str(n)

def main():
	for _ in range_n():
		s = []
		for i in range(9):
			s.append(list(input()))
		l = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
		for (i, j) in l:
			s[i][j] = replace(s[i][j])
		for i in range(9):
			print(''.join(s[i]))
main()


t = int(input())
for _ in range(t):
	a = []
	for i in range(9):
		a.append(input())
	for s in a:
		for x in s:
			if x == '1':
				print('2', end='')
			else:
				print(x, end='')
		print('\n')


N = int(input())
for i in range(0, N):
	a = input()
	x = []
	for j in range(0, 9):
		x.append(a[j])
	if x[0] == '1':
		x[0] = '2'
	else:
		x[0] = '1'
	x = ''.join(x)
	print(x)
	a = input()
	x = []
	for j in range(0, 9):
		x.append(a[j])
	if x[3] == '1':
		x[3] = '2'
	else:
		x[3] = '1'
	x = ''.join(x)
	print(x)
	a = input()
	x = []
	for j in range(0, 9):
		x.append(a[j])
	if x[6] == '1':
		x[6] = '2'
	else:
		x[6] = '1'
	x = ''.join(x)
	print(x)
	a = input()
	x = []
	for j in range(0, 9):
		x.append(a[j])
	if x[1] == '1':
		x[1] = '2'
	else:
		x[1] = '1'
	x = ''.join(x)
	print(x)
	a = input()
	x = []
	for j in range(0, 9):
		x.append(a[j])
	if x[4] == '1':
		x[4] = '2'
	else:
		x[4] = '1'
	x = ''.join(x)
	print(x)
	a = input()
	x = []
	for j in range(0, 9):
		x.append(a[j])
	if x[7] == '1':
		x[7] = '2'
	else:
		x[7] = '1'
	x = ''.join(x)
	print(x)
	a = input()
	x = []
	for j in range(0, 9):
		x.append(a[j])
	if x[2] == '1':
		x[2] = '2'
	else:
		x[2] = '1'
	x = ''.join(x)
	print(x)
	a = input()
	x = []
	for j in range(0, 9):
		x.append(a[j])
	if x[5] == '1':
		x[5] = '2'
	else:
		x[5] = '1'
	x = ''.join(x)
	print(x)
	a = input()
	x = []
	for j in range(0, 9):
		x.append(a[j])
	if x[8] == '1':
		x[8] = '2'
	else:
		x[8] = '1'
	x = ''.join(x)
	print(x)


def inc(x):
	if x < 9:
		return x + 1
	else:
		return 1
t = int(input())
pos = {0: 0, 1: 4, 2: 8, 3: 1, 4: 5, 5: 6, 6: 2, 7: 3, 8: 7}
for tt in range(t):
	lis = []
	for i in range(9):
		lis.append(input())
		imp_char = int(lis[-1][pos[i]])
		new_imp_char = inc(imp_char)
		lis[-1] = lis[-1].replace(lis[-1][pos[i]], str(new_imp_char))
	for i in range(9):
		print(lis[i])


inp = int(input())
for i in range(inp * 9):
	arr = [symb if symb != '4' else '1' for symb in input()]
	print(''.join(arr))


import math
t = int(input())
for i in range(t):
	for i in range(9):
		a = list(input())
		if i == 0:
			a[6] = a[5]
		elif i == 1:
			a[1] = a[0]
		elif i == 2:
			a[5] = a[8]
		elif i == 3:
			a[8] = a[5]
		elif i == 4:
			a[2] = a[0]
		elif i == 5:
			a[4] = a[7]
		elif i == 6:
			a[7] = a[6]
		elif i == 7:
			a[0] = a[1]
		elif i == 8:
			a[3] = a[2]
		print(''.join(a))


a = int(input())
for _ in range(a):
	z1 = list(str(input()))
	z2 = list(str(input()))
	z3 = list(str(input()))
	z4 = list(str(input()))
	z5 = list(str(input()))
	z6 = list(str(input()))
	z7 = list(str(input()))
	z8 = list(str(input()))
	z9 = list(str(input()))
	if int(z1[0]) == 1:
		z1[0] = 2
	else:
		z1[0] = 1
	if int(z2[3]) == 1:
		z2[3] = 2
	else:
		z2[3] = 1
	if int(z3[6]) == 1:
		z3[6] = 2
	else:
		z3[6] = 1
	if int(z4[1]) == 1:
		z4[1] = 2
	else:
		z4[1] = 1
	if int(z5[4]) == 1:
		z5[4] = 2
	else:
		z5[4] = 1
	if int(z6[7]) == 1:
		z6[7] = 2
	else:
		z6[7] = 1
	if int(z7[2]) == 1:
		z7[2] = 2
	else:
		z7[2] = 1
	if int(z8[5]) == 1:
		z8[5] = 2
	else:
		z8[5] = 1
	if int(z9[8]) == 1:
		z9[8] = 2
	else:
		z9[8] = 1
	for i in range(9):
		print(z1[i], end='')
	print()
	for i in range(9):
		print(z2[i], end='')
	print()
	for i in range(9):
		print(z3[i], end='')
	print()
	for i in range(9):
		print(z4[i], end='')
	print()
	for i in range(9):
		print(z5[i], end='')
	print()
	for i in range(9):
		print(z6[i], end='')
	print()
	for i in range(9):
		print(z7[i], end='')
	print()
	for i in range(9):
		print(z8[i], end='')
	print()
	for i in range(9):
		print(z9[i], end='')
	print()


t = int(input())
for _ in range(t):
	s = [[int(x) for x in list(input())] for _ in range(9)]
	change = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for (x, y) in change:
		s[x][y] = s[x][y] % 9 + 1
	for x in range(9):
		print(*s[x], sep='')


T = int(input())
for _ in range(0, T):
	L = []
	for i in range(0, 9):
		s = input()
		st = []
		for j in range(9):
			st.append(s[j])
		L.append(st)
	L[1][0] = L[0][0]
	L[2][3] = L[1][3]
	L[0][6] = L[2][6]
	L[4][1] = L[3][1]
	L[5][4] = L[4][4]
	L[3][7] = L[5][7]
	L[7][2] = L[6][2]
	L[8][5] = L[7][5]
	L[6][8] = L[8][8]
	for i in range(0, 9):
		l = ''.join(L[i])
		print(l)


for _ in range(int(input())):
	sud = []
	for i in range(9):
		a = input()
		print(a.replace('2', '1'))


def func(arr):
	if arr[0][0] == '9':
		arr[0][0] = '1'
	else:
		arr[0][0] = str(int(arr[0][0]) + 1)
	if arr[1][3] == '9':
		arr[1][3] = '1'
	else:
		arr[1][3] = str(int(arr[1][3]) + 1)
	if arr[2][6] == '9':
		arr[2][6] = '1'
	else:
		arr[2][6] = str(int(arr[2][6]) + 1)
	if arr[3][1] == '9':
		arr[3][1] = '1'
	else:
		arr[3][1] = str(int(arr[3][1]) + 1)
	if arr[4][4] == '9':
		arr[4][4] = '1'
	else:
		arr[4][4] = str(int(arr[4][4]) + 1)
	if arr[5][7] == '9':
		arr[5][7] = '1'
	else:
		arr[5][7] = str(int(arr[5][7]) + 1)
	if arr[6][2] == '9':
		arr[6][2] = '1'
	else:
		arr[6][2] = str(int(arr[6][2]) + 1)
	if arr[7][5] == '9':
		arr[7][5] = '1'
	else:
		arr[7][5] = str(int(arr[7][5]) + 1)
	if arr[8][8] == '9':
		arr[8][8] = '1'
	else:
		arr[8][8] = str(int(arr[8][8]) + 1)
	for q in range(9):
		for p in range(9):
			print(arr[q][p], end='')
		print()
n = int(input())
for m in range(n):
	sud = []
	for i in range(9):
		sud.append(list(input()))
	func(sud)


import sys
readLine = lambda : sys.stdin.readline()
readInt = lambda : int(sys.stdin.readline())
readInts = lambda : [int(x) for x in sys.stdin.readline().split(' ')]

def main():
	solns = []
	offsets = range(1, 9)
	t = readInt()
	for _ in range(t):
		sudoku = []
		for i in range(9):
			sudoku.append([int(x) for x in readLine().rstrip()])
		coords = [(0, 0), (1, 4), (2, 8), (3, 1), (4, 5), (5, 6), (6, 2), (7, 3), (8, 7)]
		for cell in coords:
			(row, col) = cell
			n = sudoku[row][col]
			n = (n + 9) % 9 + 1
			sudoku[row][col] = n
		s = []
		for row in sudoku:
			s.append(''.join((str(x) for x in row)))
		solns.append('\n'.join(s))
	print('\n'.join(solns))
main()


t = int(input())
while t != 0:
	myList = []
	for i in range(9):
		myList.append(list(map(int, input().split())))
	for i in range(9):
		myStr = str(*myList[i])
		for j in range(9):
			if myStr[j] == '7':
				myStr = myStr[:j] + '1' + myStr[j + 1:]
				myList[i] = myStr
				break
	for i in range(9):
		print(*myList[i], sep='')
	t -= 1


T = int(input())
for t in range(T):
	sudoko = []
	for row in range(9):
		row_v = list(input())
		sudoko.append(row_v)
	sudoko[0][0] = sudoko[0][1]
	sudoko[1][3] = sudoko[1][4]
	sudoko[2][6] = sudoko[2][7]
	sudoko[3][1] = sudoko[3][2]
	sudoko[4][4] = sudoko[4][5]
	sudoko[5][7] = sudoko[5][8]
	sudoko[6][2] = sudoko[6][1]
	sudoko[7][5] = sudoko[7][4]
	sudoko[8][8] = sudoko[8][7]
	for i in range(9):
		for j in range(9):
			print(sudoko[i][j], end='')
		print()


for _ in range(int(input())):
	for i in range(9):
		s = input().replace('1', '5')
		print(s)


k = int(input())
for t in range(k):
	p = []
	for y in range(9):
		p.append(input())
	for xa in range(9):
		for ya in range(9):
			if p[xa][ya] == '8':
				print(9, end='')
			else:
				print(p[xa][ya], end='')
		print()


tc = int(input())
for _ in range(tc):
	for _ in range(9):
		st = input()
		st = st.replace('9', '8')
		print(st)


def kuch(a):
	if a != 9:
		a += 1
	else:
		a -= 1
	return a
t = int(input())
for i in range(t):
	b = []
	for j in range(9):
		x = list(map(int, input()))
		b.append(x)
	b[0][0] = kuch(b[0][0])
	b[1][3] = kuch(b[1][3])
	b[2][6] = kuch(b[2][6])
	b[3][1] = kuch(b[3][1])
	b[4][4] = kuch(b[4][4])
	b[5][7] = kuch(b[5][7])
	b[6][2] = kuch(b[6][2])
	b[7][5] = kuch(b[7][5])
	b[8][8] = kuch(b[8][8])
	for j in range(9):
		a = ''
		for k in range(9):
			a = a + str(b[j][k])
		print(a)


t = int(input())
while t > 0:
	mat = []
	for i in range(9):
		s = input()
		mat.append(s)
	ans = []
	for i in mat:
		ans.append(i.replace('2', '1'))
	for i in ans:
		print(i)
	t -= 1


for _ in range(int(input())):
	mat = []
	for _ in range(9):
		mat.append(list(input()))
	for i in range(3):
		for j in range(3):
			cell = int(mat[3 * i + j][3 * j + i])
			cell += 1
			if cell == 10:
				cell = 1
			mat[3 * i + j][3 * j + i] = str(cell)
	for i in range(9):
		print(''.join(mat[i]))


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	mat = []
	for i in range(9):
		mat.append(list(input().strip()))
	for i in range(0, 3):
		for j in range(0, 3):
			if mat[3 * j + i][3 * i + j] != '2':
				mat[3 * j + i][3 * i + j] = '2'
			else:
				mat[3 * j + i][3 * i + j] = '3'
	for i in mat:
		print(''.join([str(j) for j in i]))


t = int(input())
for q in range(t):
	for j in range(9):
		s = input()
		s1 = ''
		for i in range(9):
			if s[i] == '1':
				s1 += '2'
			else:
				s1 += s[i]
		print(s1)


def answer(sudoku):
	mainPoints = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for i in range(len(mainPoints)):
		(y, x) = mainPoints[i]
		num = int(sudoku[y][x])
		if num != 9:
			sudoku[y][x] = str(num + 1)
		else:
			sudoku[y][x] = str(num - 1)
	return '\n'.join([''.join(sudoku[i]) for i in range(len(sudoku))])
testCount = int(input())
for _ in range(testCount):
	sudoku = []
	for __ in range(9):
		row = input().rstrip()
		sudoku.append([row[i] for i in range(len(row))])
	print(answer(sudoku))


for _ in range(int(input())):
	mat = []
	for i in range(9):
		mat.append(list(map(int, input())))
	for i in range(9):
		for j in range(9):
			if mat[i][j] == 1:
				mat[i][j] = 2
	for i in range(9):
		print(''.join((str(p) for p in mat[i])))


from sys import stdin, stdout

def write(_s):
	stdout.write(_s)

def writeint(_s):
	stdout.write(str(_s))

def writelist(_l):
	stdout.write(''.join(_l))

def read():
	return stdin.readline().strip()

def readint():
	return int(stdin.readline().strip())

def readints():
	return map(int, stdin.readline().strip().split(' '))
t = readint()
while t:
	sudoku = []
	for i in range(9):
		row = list(read())
		sudoku.append(row)
	off = -1
	j = 0
	for i in range(9):
		if i % 3 == 0:
			off += 1
			j = off
		if i == j == 0:
			sudoku[i][j] = sudoku[i + 1][j + 1]
		elif i % 3 == 0:
			sudoku[i][j] = sudoku[i + 1][j]
		else:
			sudoku[i][j] = sudoku[i - 1][j]
		j += 3
	for row in sudoku:
		writelist(row)
		write('\n')
	t -= 1


t = int(input())
for tc in range(t):
	s1 = list(input())
	if int(s1[0]) == 9:
		s1[0] = str(1)
	else:
		s1[0] = str(int(s1[0]) + 1)
	s2 = list(input())
	if int(s2[3]) == 9:
		s2[3] = str(1)
	else:
		s2[3] = str(int(s2[3]) + 1)
	s3 = list(input())
	if int(s3[6]) == 9:
		s3[6] = str(1)
	else:
		s3[6] = str(int(s3[6]) + 1)
	s4 = list(input())
	if int(s4[1]) == 9:
		s4[1] = str(1)
	else:
		s4[1] = str(int(s4[1]) + 1)
	s5 = list(input())
	if int(s5[4]) == 9:
		s5[4] = str(1)
	else:
		s5[4] = str(int(s5[4]) + 1)
	s6 = list(input())
	if int(s6[7]) == 9:
		s6[7] = str(1)
	else:
		s6[7] = str(int(s6[7]) + 1)
	s7 = list(input())
	if int(s7[2]) == 9:
		s7[2] = str(1)
	else:
		s7[2] = str(int(s7[2]) + 1)
	s8 = list(input())
	if int(s8[5]) == 9:
		s8[5] = str(1)
	else:
		s8[5] = str(int(s8[5]) + 1)
	s9 = list(input())
	if int(s9[8]) == 9:
		s9[8] = str(1)
	else:
		s9[8] = str(int(s9[8]) + 1)
	print(''.join(s1))
	print(''.join(s2))
	print(''.join(s3))
	print(''.join(s4))
	print(''.join(s5))
	print(''.join(s6))
	print(''.join(s7))
	print(''.join(s8))
	print(''.join(s9))


from collections import Counter

def change(x):
	if x == '9':
		return '1'
	else:
		return str(int(x) + 1)

def solve(a):
	a[0][0] = change(a[0][0])
	a[1][3] = change(a[1][3])
	a[2][6] = change(a[2][6])
	a[3][1] = change(a[3][1])
	a[4][4] = change(a[4][4])
	a[5][7] = change(a[5][7])
	a[6][2] = change(a[6][2])
	a[7][5] = change(a[7][5])
	a[8][8] = change(a[8][8])
	for x in a:
		print(''.join(x))
for _ in range(int(input())):
	a = []
	for i in range(9):
		s = input()
		a.append(list(s))
	solve(a)


def solve():
	grid = []
	for _ in range(9):
		grid.append([int(i) for i in input()])
	grid[0][0] = grid[0][0] % 9 + 1
	grid[1][3] = grid[1][3] % 9 + 1
	grid[2][6] = grid[2][6] % 9 + 1
	grid[3][1] = grid[3][1] % 9 + 1
	grid[4][4] = grid[4][4] % 9 + 1
	grid[5][7] = grid[5][7] % 9 + 1
	grid[6][2] = grid[6][2] % 9 + 1
	grid[7][5] = grid[7][5] % 9 + 1
	grid[8][8] = grid[8][8] % 9 + 1
	for i in range(9):
		print(''.join([str(i) for i in grid[i]]))
t = int(input())
for _ in range(t):
	solve()


import sys
t = int(sys.stdin.readline())
mods = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for _ in range(t):
	for i in range(9):
		row = sys.stdin.readline().split()[0]
		mod = mods[i]
		if row[mod] != '2':
			row = row[:mod] + '2' + row[mod + 1:]
		else:
			row = row[:mod] + '1' + row[mod + 1:]
		print(row)


for _ in range(int(input())):
	arr = []
	for i in range(9):
		arr.append(input())
	arr2 = []
	x = [0, 1, 2, 3, 4, 5, 6, 7, 8]
	y = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	indx = 0
	for i in range(9):
		s = ''
		for j in range(9):
			if i == x[indx] and j == y[indx]:
				if arr[i][j] != '1':
					s += str(1)
				else:
					s += str(2)
				indx += 1
			else:
				s += arr[i][j]
		arr2.append(s)
		s = ''
	for i in arr2:
		print(i)


N = int(input())
for i in range(N):
	matrix = []
	for k in range(9):
		a = []
		a = list(map(str, input()))
		ind = a.index('1')
		a.remove('1')
		a.insert(ind, '2')
		matrix.append(a)
	for j in range(9):
		print(''.join(matrix[j]))


for _ in range(int(input())):
	a = [0] * 9
	for i in range(9):
		a[i] = list(input())
		a[i][a[i].index('2')] = '1'
		print(''.join(a[i]))


for i in range(int(input())):
	a = []
	t = 0
	j = 0
	for i in range(9):
		a.append(list(input()))
	for i in range(9):
		if a[j][i] == '9':
			a[j][i] = '1'
		else:
			a[j][i] = str(1 + int(a[j][i]))
		j += 3
		if j > 8:
			t += 1
			j = t
	for i in range(9):
		print(''.join(a[i]))


t = int(input())
for x in range(t):
	l = []
	for y in range(9):
		s = input()
		m = []
		for k in s:
			m.append(int(k))
		l.append(m)
	i = 0
	j = 0
	while i < 9:
		if l[i][j] == 9:
			l[i][j] = 1
		else:
			l[i][j] = l[i][j] + 1
		i = i + 1
		z = j + 3
		if z == 8:
			j = 8
		else:
			j = z % 8
	for y in range(9):
		for k in range(9):
			print(l[y][k], end='')
		print()


t = [int(i) for i in input().split(' ')][0]
for _ in range(t):
	sudoku = []
	for x in range(9):
		data = list([i for i in input().split(' ')][0])
		sudoku.append(data)
	for i in range(3):
		sudoku[i][i * 3] = sudoku[i][i * 3 + 1]
	for i in range(3):
		sudoku[i + 3][i * 3 + 1] = sudoku[i + 3][i * 3 + 2]
	for i in range(3):
		sudoku[i + 6][2 + i * 3] = sudoku[i + 6][1 + i * 3]
	for line in sudoku:
		print(''.join(line))


t = int(input())
for _ in range(t):
	ans = list()
	for _ in range(9):
		ans.append(input().replace('9', '1'))
	for v in ans:
		print(''.join(v))


for _ in range(int(input())):
	l = []
	j = 0
	for i in range(9):
		s1 = input()
		l.append(s1)
	i = 0
	j = 0
	k = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	k1 = [1, 2, 1, 4, 5, 4, 7, 8, 7]
	for i in range(9):
		s = l[i]
		sn = l[k1[i]]
		j = k[i]
		s = s[:j] + sn[j] + s[j + 1:]
		l[i] = s
	for i in l:
		print(i)


t = int(input())
for z in range(t):
	for q in range(9):
		s = input().replace('1', '2')
		print(s)


places = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
for _ in range(int(input())):
	su = []
	for _ in range(9):
		su.append(list(map(int, list(input()))))
	bad = su.copy()
	for t in places:
		bad[t[0]][t[1]] = bad[t[0]][t[1]] % 9 + 1
	for row in bad:
		print(''.join([str(i) for i in row]))


def fun(a):
	if a < 9:
		return a + 1
	else:
		return a - 1
t = int(input())
while t:
	t = t - 1
	suduko = []
	suduko.append([w for w in input()])
	suduko.append([w for w in input()])
	suduko.append([w for w in input()])
	suduko.append([w for w in input()])
	suduko.append([w for w in input()])
	suduko.append([w for w in input()])
	suduko.append([w for w in input()])
	suduko.append([w for w in input()])
	suduko.append([w for w in input()])
	suduko[0][0] = str(fun(int(suduko[0][0])))
	suduko[1][3] = str(fun(int(suduko[1][3])))
	suduko[2][6] = str(fun(int(suduko[2][6])))
	suduko[3][1] = str(fun(int(suduko[3][1])))
	suduko[4][4] = str(fun(int(suduko[4][4])))
	suduko[5][7] = str(fun(int(suduko[5][7])))
	suduko[6][2] = str(fun(int(suduko[6][2])))
	suduko[7][5] = str(fun(int(suduko[7][5])))
	suduko[8][8] = str(fun(int(suduko[8][8])))
	for i in range(9):
		for j in range(9):
			print(suduko[i][j], end='')
		print()


t = int(input())
for i in range(0, t):
	for j in range(0, 9):
		x = list(input())
		for k in range(0, 9):
			if x[k] == '2':
				x[k] = '1'
		y = ''
		for l in range(0, 9):
			y = y + x[l]
		print(y)


def giveMeANumber(n):
	if n != 3:
		return 3
	else:
		return 4

def main():
	t = int(input())
	for _ in range(t):
		a = []
		for i in range(9):
			x = input()
			a.append(list(map(int, list(x))))
		b = [0, 3, 6, 1, 4, 7, 2, 5, 8]
		for i in range(9):
			a[i][b[i]] = giveMeANumber(a[i][b[i]])
		for i in range(9):
			for j in range(9):
				print(a[i][j], end='')
			print()
main()


t = int(input())
for _ in range(t):
	for k in range(9):
		temp = input()
		print(temp.replace('2', '1'))


import sys
t = int(input())
for _ in range(t):
	grid = [[int(c) for c in input()] for i in range(9)]
	grid[0][0] = 1 + grid[0][0] % 9
	grid[1][3] = 1 + grid[1][3] % 9
	grid[2][6] = 1 + grid[2][6] % 9
	grid[3][1] = 1 + grid[3][1] % 9
	grid[4][4] = 1 + grid[4][4] % 9
	grid[5][7] = 1 + grid[5][7] % 9
	grid[6][2] = 1 + grid[6][2] % 9
	grid[7][5] = 1 + grid[7][5] % 9
	grid[8][8] = 1 + grid[8][8] % 9
	for row in grid:
		print(*row, sep='')


for mdaaaaaa in range(int(input())):
	a = []
	for i in range(9):
		tmp = input()
		a.append([])
		for x in tmp:
			a[-1].append(x)
	arr = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for x in arr:
		i = x[0]
		j = x[1]
		if a[i][j] == '9':
			a[i][j] = '1'
		else:
			a[i][j] = chr(ord(a[i][j]) + 1)
	for i in range(9):
		for x in a[i]:
			print(x, end='')
		print()


for _ in range(int(input()) * 9):
	print(input().replace('3', '4'))


tuples = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
t = int(input())
for g in range(t):
	M = list()
	for l in range(9):
		L = list()
		S = input()
		for k in range(9):
			L.append(int(S[k]))
		M.append(L)
	for (a, b) in tuples:
		if M[a][b] < 9:
			M[a][b] += 1
		else:
			M[a][b] = 1
	for i in range(9):
		S = str()
		for j in range(9):
			S += str(M[i][j])
		if i < 8:
			print(S)
		else:
			print(S)
			print()


for _ in range(int(input())):
	for i in range(9):
		print(input().replace('9', '1'))


t = int(input())
while t:
	l1 = input()
	l1 = list(l1)
	l2 = input()
	l2 = list(l2)
	l3 = input()
	l3 = list(l3)
	l4 = input()
	l4 = list(l4)
	l5 = input()
	l5 = list(l5)
	l6 = input()
	l6 = list(l6)
	l7 = input()
	l7 = list(l7)
	l8 = input()
	l8 = list(l8)
	l9 = input()
	l9 = list(l9)
	l1[0] = l2[0]
	l2[3] = l3[3]
	l3[6] = l1[6]
	l4[1] = l5[1]
	l5[4] = l6[4]
	l6[7] = l4[7]
	l7[2] = l8[2]
	l8[5] = l9[5]
	l9[8] = l7[8]
	for i in l1:
		print(i, end='')
	print('')
	for i in l2:
		print(i, end='')
	print('')
	for i in l3:
		print(i, end='')
	print('')
	for i in l4:
		print(i, end='')
	print('')
	for i in l5:
		print(i, end='')
	print('')
	for i in l6:
		print(i, end='')
	print('')
	for i in l7:
		print(i, end='')
	print('')
	for i in l8:
		print(i, end='')
	print('')
	for i in l9:
		print(i, end='')
	print('')
	t = t - 1


import sys
from random import choice, randint
inp = sys.stdin.readline
out = sys.stdout.write
flsh = sys.stdout.flush
sys.setrecursionlimit(10 ** 9)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, inp().strip().split())

def LI():
	return list(map(int, inp().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in inp().strip().split()]

def LF():
	return [float(x) for x in inp().strip().split()]

def LS():
	return inp().strip().split()

def I():
	return int(inp().strip())

def F():
	return float(inp().strip())

def S():
	return inp().strip()

def pf(s):
	return out(s + '\n')

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	t = I()
	for _ in range(t):
		l = []
		for i in range(9):
			s = S()
			res = ''
			for i in range(9):
				if s[i] == '5':
					res = s[:i] + '3' + s[i + 1:]
			l.append(res)
		for i in range(9):
			print(l[i])
main()


from sys import stdin
import sys
for _ in range(int(stdin.readline())):
	arr = []
	for i in range(9):
		arr.append(list(stdin.readline().rstrip()))
	for i in range(9):
		for j in range(9):
			if arr[i][j] == '1':
				arr[i][j] = '5'
				break
		print(''.join(arr[i]))


import sys
input = sys.stdin.buffer.readline

def change(i):
	if i != 9:
		return i + 1
	else:
		return 1
t = int(input())
for _ in range(t):
	M = [int(input()) for i in range(9)]
	M = [str(a) for a in M]
	M = [list(a) for a in M]
	M = [list(map(int, a)) for a in M]
	M[0][0] = change(M[0][0])
	M[1][3] = change(M[1][3])
	M[2][6] = change(M[2][6])
	M[3][1] = change(M[3][1])
	M[4][4] = change(M[4][4])
	M[5][7] = change(M[5][7])
	M[6][2] = change(M[6][2])
	M[7][5] = change(M[7][5])
	M[8][8] = change(M[8][8])
	for i in range(9):
		a = M[i]
		print(''.join(list(map(str, a))))


import math

def findPossible(grid, prevCols, prevBlocks, prevN, firstN, i):
	if i == 9:
		if grid[8][prevCols[8]] != firstN:
			return prevCols
		else:
			return False
	for j in range(9):
		if not j in prevCols and (not math.floor(j / 3) + 3 * math.floor(i / 3) in prevBlocks) and (grid[i][j] != prevN):
			pos = findPossible(grid, prevCols + [j], prevBlocks + [math.floor(j / 3) + 3 * math.floor(i / 3)], grid[i][j], firstN, i + 1)
			if pos != False:
				return pos
	return False
T = int(input())
for t in range(T):
	grid = []
	for i in range(9):
		grid.append([i for i in input()])
	for j in range(9):
		changes = findPossible(grid, [j], [math.floor(j / 3)], grid[0][j], grid[0][j], 1)
		if changes != False:
			break
	first = grid[0][changes[0]]
	for i in range(len(changes) - 1):
		grid[i][changes[i]] = grid[i + 1][changes[i + 1]]
	grid[8][changes[8]] = first
	for r in grid:
		row = ''.join(r)
		print(row)


def main():
	for _ in range(int(input())):
		matrix = []
		for i in range(9):
			s = input()
			row = []
			for j in range(len(s)):
				row.append(ord(s[j]) - ord('0'))
			matrix.append(row)
		for i in range(0, 9):
			for j in range(0, 9):
				if matrix[i][j] == 1:
					matrix[i][j] = 2
		for i in range(9):
			for j in range(9):
				cout << matrix[i][j]
			cout << '\n'
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'
main()


t = int(input())
for _ in range(t):
	l = []
	for i in range(9):
		s = input()
		arr = []
		for i in range(len(s)):
			arr.append(int(s[i]))
		l.append(arr)
	if l[0][0] == 1 or l[0][0] == 5:
		l[0][0] = 2
	else:
		l[0][0] = 9 - l[0][0] + 1
	if l[1][4] == 1 or l[1][4] == 5:
		l[1][4] = 2
	else:
		l[1][4] = 9 - l[1][4] + 1
	if l[2][8] == 1 or l[2][8] == 5:
		l[2][8] = 2
	else:
		l[2][8] = 9 - l[2][8] + 1
	if l[3][1] == 1 or l[3][1] == 5:
		l[3][1] = 2
	else:
		l[3][1] = 9 - l[3][1] + 1
	if l[4][3] == 1 or l[4][3] == 5:
		l[4][3] = 2
	else:
		l[4][3] = 9 - l[4][3] + 1
	if l[5][6] == 1 or l[5][6] == 5:
		l[5][6] = 2
	else:
		l[5][6] = 9 - l[5][6] + 1
	if l[6][2] == 1 or l[6][2] == 5:
		l[6][2] = 2
	else:
		l[6][2] = 9 - l[6][2] + 1
	if l[7][5] == 1 or l[7][5] == 5:
		l[7][5] = 2
	else:
		l[7][5] = 9 - l[7][5] + 1
	if l[8][7] == 1 or l[8][7] == 5:
		l[8][7] = 2
	else:
		l[8][7] = 9 - l[8][7] + 1
	for i in range(9):
		p = ''
		for j in range(9):
			p += str(l[i][j])
		print(p)


def convertArrayToInt(A):
	for i in range(0, len(A), 1):
		A[i] = int(A[i])
	return A
testCases = int(input())

def makeAntiSudoku(matrix):
	cols = [1, 4, 7, 2, 5, 8, 3, 6, 0]
	j = 0
	for i in range(0, 9, 1):
		matrix[i][cols[j] - 1] = matrix[i][cols[j]]
		j += 1
	for i in range(0, 9, 1):
		for j in range(0, 9, 1):
			print(matrix[i][j], end='')
		print()

def split(word):
	return [char for char in word]
while testCases:
	matrix = []
	n = 9
	while n > 0:
		X = input()
		X = split(X)
		matrix.append(X)
		n -= 1
	makeAntiSudoku(matrix)
	testCases -= 1


t = int(input())
for _ in range(t * 9):
	print(input().replace('1', '9'))


for t in range(int(input())):
	row = [[], [], [], [], [], [], [], [], []]
	for i in range(9):
		l = input()
		for j in range(9):
			row[i].append(l[j])
	row[0][0] = row[0][1]
	row[1][3] = row[1][4]
	row[2][6] = row[2][7]
	row[3][1] = row[3][2]
	row[4][4] = row[4][5]
	row[5][7] = row[5][8]
	row[6][2] = row[6][3]
	row[7][5] = row[7][6]
	row[8][8] = row[8][7]
	for i in range(9):
		string = ''
		for j in range(9):
			string += row[i][j]
		print(string)


import sys, math, cmath, time, io, os
start_time = time.time()

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

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

def insr():
	s = input()
	return s[:len(s)]

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

def qw(n):
	n = n + 1
	if n == 10:
		n = 8
	return str(n)

def solve():
	a = []
	for i in range(9):
		s = insr()
		a.append(list(s))
	a[0][0] = qw(int(a[0][0]))
	a[1][3] = qw(int(a[1][3]))
	a[2][6] = qw(int(a[2][6]))
	a[3][1] = qw(int(a[3][1]))
	a[4][4] = qw(int(a[4][4]))
	a[5][7] = qw(int(a[5][7]))
	a[6][2] = qw(int(a[6][2]))
	a[7][5] = qw(int(a[7][5]))
	a[8][8] = qw(int(a[8][8]))
	for i in range(9):
		print(*a[i], sep='')
	print()

def main():
	ONLINE_JUDGE = __debug__
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
	sys.stdout.close()

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q
ONLINE_JUDGE = not __debug__
if ONLINE_JUDGE:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
	out = __pypy__.builders.StringBuilder()
	if sys.version_info[0] < 3:
		os.write(1, out.build())
	else:
		os.write(1, out.build().encode())
main()


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def print_list_int(l):
	print(''.join(map(str, map(int, l))))
t = inp()
for test in range(t):
	a = []
	for _ in range(9):
		a.append(list(input().strip()))
	for row in a:
		ind = row.index('1')
		if ind == 0:
			row[2] = 1
		elif ind == 3:
			row[5] = 1
		elif ind == 6:
			row[8] = 1
		else:
			row[ind - 1] = 1
	for row in a:
		print_list_int(row)


for _ in range(int(input())):
	su = []
	for i in range(9):
		s = input()
		tmp = []
		for i in s:
			tmp.append(int(i))
		su.append(tmp)
	su[0][0] = su[0][0] % 9 + 1
	su[1][4] = su[1][4] % 9 + 1
	su[2][8] = su[2][8] % 9 + 1
	su[3][1] = su[3][1] % 9 + 1
	su[4][5] = su[4][5] % 9 + 1
	su[5][6] = su[5][6] % 9 + 1
	su[6][2] = su[6][2] % 9 + 1
	su[7][3] = su[7][3] % 9 + 1
	su[8][7] = su[8][7] % 9 + 1
	for i in su:
		print(*i, sep='')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	a = 0
	b = 3
	c = 6
	for i in range(3):
		l1 = list(input())
		l2 = list(input())
		l3 = list(input())
		if i < 2:
			l1[a] = l1[a + 1]
			l2[b] = l2[b + 1]
			l3[c] = l3[c + 1]
		else:
			l1[a] = l1[a - 1]
			l2[b] = l2[b - 1]
			l3[c] = l3[c - 1]
		a += 1
		b += 1
		c += 1
		print(''.join((str(x) for x in l1)))
		print(''.join((str(x) for x in l2)))
		print(''.join((str(x) for x in l3)))


from sys import stdin
t = int(stdin.readline())
while t > 0:
	s = []
	for i in range(9):
		a = stdin.readline()
		s.append(a)
	ans = []
	z = [1, 4, 7, 2, 5, 8, 3, 6, 9]
	for i in range(0, 9):
		y = z[i]
		x = s[i][y - 1]
		x = int(x)
		if x == 9:
			x = 1
		else:
			x = x + 1
		ans.append(s[i][:y - 1] + str(x) + s[i][y:])
	for i in range(9):
		print(ans[i], end='')
	t -= 1


t = int(input())
for _ in range(t):
	sudoku = []
	for i in range(9):
		sudoku.append([int(x) for x in input()])
	for i in range(9):
		sudoku[i][sudoku[i].index(2)] = 1
	for i in range(9):
		for j in range(9):
			print(sudoku[i][j], end='')
		print()


t = int(input())
while t:
	mat = []
	for i in range(9):
		s = input()
		mat.append(list(map(lambda x: int(x), s)))
	mat[0][1] = mat[0][0]
	mat[3][0] = mat[3][1]
	mat[6][2] = mat[6][1]
	mat[1][4] = mat[1][3]
	mat[4][3] = mat[4][4]
	mat[7][5] = mat[7][4]
	mat[2][7] = mat[2][6]
	mat[5][6] = mat[5][7]
	mat[8][8] = mat[8][7]
	for row in mat:
		for x in row:
			print(x, end='')
		print()
	t -= 1


import sys

def search(depth: int, table: [[int]], usedRow: [int], usedCol: [int], usedBox: [int], ans: [int]) -> bool:
	if len(ans) == 9:
		return True
	flag = False
	for i in range(9):
		if i in usedCol:
			continue
		if 3 * (depth // 3) + i // 3 in usedBox:
			continue
		newUsedRow = usedRow[:]
		newUsedRow.append(depth)
		newUsedCol = usedCol[:]
		newUsedCol.append(i)
		newUsedBox = usedBox[:]
		newUsedBox.append(3 * (depth // 3) + i // 3)
		ans.append([depth, i])
		flag = search(depth + 1, table, newUsedRow, newUsedCol, newUsedBox, ans)
		if flag:
			break
		ans.pop()
	return flag

def main():
	t = int(input())
	for _ in range(t):
		table = []
		for i in range(9):
			temp = sys.stdin.readline().strip()
			table.append([])
			for j in temp:
				table[-1].append(j)
		for i in range(9):
			ans = [[0, i]]
			flag = search(1, table, [0], [i], [i // 3], ans)
			if flag:
				break
		for i in ans:
			table[i[0]][i[1]] = int(table[i[0]][i[1]]) + 1
			if table[i[0]][i[1]] == 10:
				table[i[0]][i[1]] = 1
		for i in table:
			temp = ''
			for j in i:
				temp += str(j)
			print(temp)
	return
main()


import sys
import math

def solve(A):
	n = 3
	(rows, cols) = (n * n, n * n)
	for row in range(rows):
		one_index_col = A[row].index('1')
		next_col = (one_index_col + 1) % n + one_index_col // n * n
		A[row][next_col] = '1'
	return A

def print_arr(A):
	for i in range(len(A)):
		row_str = ''.join(A[i])
		print(row_str)
t = int(input())
for _ in range(t):
	A = []
	for _ in range(9):
		row = str(input())
		A.append([x for x in row])
	print_arr(solve(A))


for _ in range(int(input())):
	s = []
	for __ in range(9):
		s.append(list(map(int, list(input()))))
	row = -3
	for i in range(3):
		row += 3
		col = i
		for j in range(3):
			if s[row + j][col] != 5:
				s[row + j][col] = 10 - s[row + j][col]
			else:
				s[row + j][col] = 1
			col += 3
	for i in range(9):
		print(''.join([str(x) for x in s[i]]))


import atexit
import io
import sys
from string import printable
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def which_block(i, j):
	return i // 3 * 3 + j // 3

def baseconvert(n, base):
	digits = printable[:-6]
	s = ''
	while 1:
		rm = n % base
		s = digits[rm] + s
		n //= base
		if n == 0:
			break
	return s

def main():
	for _ in range(int(input())):
		so = []
		for i in range(9):
			so.append(list(input().strip()))
		for i in range(3):
			for j in range(3):
				ti = i * 3 + j
				tj = i + 3 * j
				so[ti][tj] = str(int(so[ti][tj]) % 9 + 1)
		for i in so:
			print(''.join(i))
main()


t = int(input())
while t > 0:
	a = []
	for i in range(9):
		k = input()
		a.append(k)
	a[0] = a[0][1] + a[0][1:]
	a[1] = a[1][:3] + a[1][2] + a[1][4:]
	a[2] = a[2][:6] + a[2][5] + a[2][7:]
	a[3] = a[3][0] + a[3][0] + a[3][2:]
	a[4] = a[4][:4] + a[4][3] + a[4][5:]
	a[5] = a[5][:7] + a[5][6] + a[5][8:]
	a[6] = a[6][:2] + a[6][1] + a[6][3:]
	a[7] = a[7][:5] + a[7][4] + a[7][6:]
	a[8] = a[8][:8] + a[8][7] + a[8][9:]
	for i in range(9):
		print(a[i])
	t -= 1


T = int(input())
for test in range(T):
	seed = [0, 4, 8, 1, 5, 6, 2, 3, 7]
	for x in range(9):
		line = input()
		change = seed[x]
		correct = int(line[change])
		incorrect = correct % 9 + 1
		line = line[:change] + str(incorrect) + line[change + 1:]
		print(line)


for T in range(int(input())):
	mat = []
	x = 0
	for i in range(9):
		arr = input()
		mat.append(arr)
	x = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		j = x[i]
		for k in range(9):
			if k == j:
				if mat[i][j] == '9':
					print(1, end='')
				else:
					print('9', end='')
			else:
				print(mat[i][k], end='')
		print()


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def solve(n):
	return n * (n + 1) // 2
t = int(input())
for i in range(t):
	l = []
	for i in range(9):
		la = list(input())
		l.append(la)
	cnt = 0
	for i in range(9):
		z = l[i][0]
		if i == 0:
			l[i][3] = z
		if i == 1:
			l[i][6] = z
		if i == 2:
			l[i][2] = z
		if i == 3:
			l[i][4] = z
		if i == 4:
			l[i][7] = z
		if i == 5:
			l[i][1] = z
		if i == 6:
			l[i][5] = z
		if i == 7:
			l[i][8] = z
		if i == 8:
			l[i][0] = l[0][0]
	for i in l:
		print(''.join(i))


nbT = int(input())
for i in range(nbT):
	sudoku = list()
	for j in range(9):
		sudoku.append(list(map(int, input())))
	sudoku[0][0] = max((sudoku[0][0] + 1) % 10, 1)
	sudoku[3][1] = max((sudoku[3][1] + 1) % 10, 1)
	sudoku[6][2] = max((sudoku[6][2] + 1) % 10, 1)
	sudoku[1][3] = max((sudoku[1][3] + 1) % 10, 1)
	sudoku[4][4] = max((sudoku[4][4] + 1) % 10, 1)
	sudoku[7][5] = max((sudoku[7][5] + 1) % 10, 1)
	sudoku[2][6] = max((sudoku[2][6] + 1) % 10, 1)
	sudoku[5][7] = max((sudoku[5][7] + 1) % 10, 1)
	sudoku[8][8] = max((sudoku[8][8] + 1) % 10, 1)
	for j in range(9):
		out = ''
		for i in range(9):
			out += str(sudoku[j][i])
		print(out)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect

def solution():
	for i in range(int(input())):
		n = []
		for i in range(0, 9):
			n.append(list(input()))
		for i in range(9):
			for j in range(9):
				if n[i][j] == '2':
					n[i][j] = '3'
				print(n[i][j], end='')
			print()
solution()
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))


t = int(input())

def n(x):
	ans = 1 if int(x) + 1 == 10 else int(x) + 1
	return str(ans)
for i in range(t):
	grid = []
	for i in range(9):
		grid.append(list(input()))
	grid[0][0] = n(grid[0][0])
	grid[1][3] = n(grid[1][3])
	grid[2][6] = n(grid[2][6])
	grid[3][1] = n(grid[3][1])
	grid[4][4] = n(grid[4][4])
	grid[5][7] = n(grid[5][7])
	grid[6][2] = n(grid[6][2])
	grid[7][5] = n(grid[7][5])
	grid[8][8] = n(grid[8][8])
	for i in range(9):
		print(''.join(grid[i]))


from collections import Counter
for _ in range(int(input())):
	a = [list(input()) for o in range(9)]
	kok = 0
	kek = 0
	for i in range(9):
		kek = i // 3
		if a[kok + kek][i] != '1':
			a[kok + kek][i] = '1'
		else:
			a[kok + kek][i] = '2'
		kok = (kok + 3) % 9
	for elem in a:
		print(''.join(elem))


T = int(input())
for _ in range(T):
	s = []
	for _ in range(9):
		tmp = input()
		s.append(list(map(int, list(tmp))))
	for i in range(3):
		d = i
		for j in range(3):
			x = i * 3 + d
			y = j * 3 + d
			v = s[i * 3 + (d + 1) % 3][j * 3 + (d + 1) % 3]
			s[x][y] = v
			d = (d + 1) % 3
	print('\n'.join([''.join(list(map(str, s[i]))) for i in range(9)]))


for _ in range(0, int(input())):
	sud = [0] * 9
	for i in range(0, 9):
		t = [0] * 9
		xi = input()
		for j in range(0, 9):
			x = xi[j]
			t[j] = int(x)
		sud[i] = t
	l = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(0, 9):
		if sud[i][l[i]] != 2:
			sud[i][l[i]] = 2
		else:
			sud[i][l[i]] = 3
	for i in range(0, 9):
		s = ''
		for j in range(0, 9):
			s += str(sud[i][j])
		print(s)


for _ in range(int(input())):
	for i in range(1, 10):
		r = input()
		s = list(r)
		res = ''
		for j in s:
			if j == '1':
				j = '2'
			res += j
		print(res)


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	sod = []
	for i in range(9):
		sod.append(list(map(int, list(is1()))))
	num = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for i in num:
		cur = sod[i[0]][i[1]]
		if cur != 1:
			cur -= 1
		else:
			cur += 1
		sod[i[0]][i[1]] = cur
	for i in sod:
		print(*i, sep='')


import sys
import collections
import threading
import string

def main():
	testn = int(input())
	for _ in range(testn):
		a = [list(input()[:9]) for _ in range(9)]
		for i in range(9):
			for j in range(9):
				if a[i][j] == '1':
					a[i][j] = '9'
			print(''.join(a[i]))
input = sys.stdin.readline
main()


import sys
input = sys.stdin.buffer.readline
ans = []
for _ in range(int(input())):
	sudoku = [0 for _ in range(9)]
	for i in range(9):
		sudoku[i] = list(map(chr, list(input())))
	sudoku[0][0] = sudoku[0][1]
	sudoku[1][3] = sudoku[1][4]
	sudoku[2][6] = sudoku[2][7]
	sudoku[3][1] = sudoku[3][2]
	sudoku[4][4] = sudoku[4][5]
	sudoku[5][7] = sudoku[5][8]
	sudoku[6][2] = sudoku[6][1]
	sudoku[7][5] = sudoku[7][4]
	sudoku[8][8] = sudoku[8][7]
	for i in range(9):
		for j in range(9):
			print(sudoku[i][j], end='')
		print()


for x in range(int(input())):
	for i in range(9):
		print(input().replace('1', '5'))


i = int(input())
for _ in range(i):
	for _ in range(9):
		a = list(map(int, list(input())))
		for i in a:
			if i == 1:
				i = 2
			print(i, end='')
		print('\n')


def solve():
	puzzle = []
	for i in range(9):
		puzzle.append(input())
	positions = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		row = puzzle[i]
		index = positions[i]
		value = row[index]
		if index < 8:
			replacement = puzzle[i][index + 1]
		else:
			replacement = puzzle[i][index - 1]
		puzzle[i] = puzzle[i][:index] + replacement + puzzle[i][index + 1:]
	print('\n'.join(puzzle))
t = int(input())
for i in range(t):
	solve()


t = int(input())
for i in range(t):
	matrix = []
	for j in range(9):
		matrix.append([int(x) for x in input()])
	matrix[0][0] = (matrix[0][0] + 1) % 9 + 1
	matrix[1][3] = (matrix[1][3] + 1) % 9 + 1
	matrix[2][6] = (matrix[2][6] + 1) % 9 + 1
	matrix[3][1] = (matrix[3][1] + 1) % 9 + 1
	matrix[4][4] = (matrix[4][4] + 1) % 9 + 1
	matrix[5][7] = (matrix[5][7] + 1) % 9 + 1
	matrix[6][2] = (matrix[6][2] + 1) % 9 + 1
	matrix[7][5] = (matrix[7][5] + 1) % 9 + 1
	matrix[8][8] = (matrix[8][8] + 1) % 9 + 1
	for el in matrix:
		print(*el, sep='')


for _ in range(int(input())):
	mat = []
	for i in range(9):
		str1 = list(input())
		mat.append(str1)
	j = 0
	count = 0
	t = 0
	for i in range(9):
		if j == 0:
			mat[i][j] = mat[i][8]
			count += 1
		else:
			mat[i][j] = mat[i][j - 1]
			count += 1
		if count == 3:
			t += 1
			j = t
			count = 0
		else:
			j = (j + 3) % 9
	for i in range(9):
		for j in range(9):
			print(mat[i][j], end='')
		print('')


def yo():
	t = int(input())
	for i in range(t):
		for a in range(3):
			for b in range(3):
				line = input()
				print(line[:a + b * 3] + str(int(line[a + b * 3]) % 9 + 1) + line[a + 1 + b * 3:])

def boi():
	t = int(input().strip())
	for i in range(9 * t):
		print(input().strip().replace('1', '2'))
boi()


t = int(input())
while t:
	t -= 1
	count = 0
	ll = []
	for i in range(0, 9):
		a = [int(x) for x in input()]
		count = i // 3
		for i in range(0, 9):
			if a[i] == 1:
				a[i] = 2
		a = [str(x) for x in a]
		a = ''.join(a)
		ll.append(a)
	for a in ll:
		print(a)


t = int(input())
while t:
	t -= 1
	for i in range(9):
		s = input()
		for j in range(9):
			print('2' if s[j] == '1' else s[j], end='')
		print('')


import random
t = int(input())
while t > 0:
	matrix = []
	for i in range(9):
		lister = input()
		temp = [int(d) for d in lister]
		matrix.append(temp)
	indices = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		numb = random.randint(1, 9)
		while matrix[i][indices[i]] == numb:
			numb = random.randint(1, 9)
		matrix[i][indices[i]] = numb
	for i in range(9):
		print(int(''.join(map(str, matrix[i]))))
	t -= 1


t = int(input())
for _ in range(t):
	a = []
	for __ in range(9):
		x = input()
		a.append(list(x))
	if a[0][0] != '1':
		a[0][0] = '1'
	else:
		a[0][0] = '2'
	if a[1][3] != '1':
		a[1][3] = '1'
	else:
		a[1][3] = '2'
	if a[2][6] != '1':
		a[2][6] = '1'
	else:
		a[2][6] = '2'
	if a[3][1] != '1':
		a[3][1] = '1'
	else:
		a[3][1] = '2'
	if a[4][4] != '1':
		a[4][4] = '1'
	else:
		a[4][4] = '2'
	if a[5][7] != '1':
		a[5][7] = '1'
	else:
		a[5][7] = '2'
	if a[6][2] != '1':
		a[6][2] = '1'
	else:
		a[6][2] = '2'
	if a[7][5] != '1':
		a[7][5] = '1'
	else:
		a[7][5] = '2'
	if a[8][8] != '1':
		a[8][8] = '1'
	else:
		a[8][8] = '2'
	for x in a:
		print(''.join(x))


a = int(input())
for x in range(a):
	for l in range(9):
		s = input()
		s = s.replace('1', '4')
		print(s)


t = int(input())
for i in range(t):
	board = []
	for j in range(9):
		row = input()
		temp = []
		for ch in row:
			if ch == '1':
				temp.append('2')
			else:
				temp.append(ch)
		board.append(temp)
	for j in range(9):
		print(''.join(board[j]))


t = int(input())
for i in range(t):
	sudoku = [list(input()) for i in range(9)]
	sudoku[0][0] = sudoku[0][2]
	sudoku[4][1] = sudoku[4][0]
	sudoku[8][2] = sudoku[8][1]
	sudoku[1][3] = sudoku[1][5]
	sudoku[5][4] = sudoku[5][3]
	sudoku[6][5] = sudoku[6][4]
	sudoku[2][6] = sudoku[2][8]
	sudoku[3][7] = sudoku[3][6]
	sudoku[7][8] = sudoku[7][7]
	sudoku = [''.join(sudoku[i]) for i in range(9)]
	print('\n'.join(sudoku))


for i in range(int(input())):
	sud = []
	for j in range(9):
		temp1 = input()
		temp2 = []
		for k in temp1:
			temp2.append(int(k))
		sud.append(temp2)
	sud[0][0] = sud[0][0] % 9 + 1
	sud[1][3] = sud[1][3] % 9 + 1
	sud[2][6] = sud[2][6] % 9 + 1
	sud[3][1] = sud[3][1] % 9 + 1
	sud[4][4] = sud[4][4] % 9 + 1
	sud[5][7] = sud[5][7] % 9 + 1
	sud[6][2] = sud[6][2] % 9 + 1
	sud[7][5] = sud[7][5] % 9 + 1
	sud[8][8] = sud[8][8] % 9 + 1
	for j in range(9):
		s = ''
		for k in sud[j]:
			s += str(k)
		print(s[:9])


try:
	n = int(input())
	for i in range(n):
		a = int(input())
		b = int(input())
		c = int(input())
		d = int(input())
		e = int(input())
		f = int(input())
		g = int(input())
		h = int(input())
		i = int(input())
		a = str(a).replace('1', '2')
		b = str(b).replace('1', '2')
		c = str(c).replace('1', '2')
		d = str(d).replace('1', '2')
		e = str(e).replace('1', '2')
		f = str(f).replace('1', '2')
		g = str(g).replace('1', '2')
		h = str(h).replace('1', '2')
		i = str(i).replace('1', '2')
		print(a)
		print(b)
		print(c)
		print(d)
		print(e)
		print(f)
		print(g)
		print(h)
		print(i)
except:
	pass


import math
t = int(input())
for i in range(t):
	a = []
	for j in range(9):
		a.append(list(input().strip()))
	for j in range(9):
		for k in range(9):
			if a[j][k] == '1':
				a[j][k] = '2'
	for v in a:
		print(''.join(v))


from sys import stdin

def solve(tc):
	ans = []
	for i in range(9):
		s = stdin.readline().strip()
		for ch in s:
			if ch == '1':
				ans.append('9')
			else:
				ans.append(ch)
		ans.append('\n')
	print(''.join(ans))
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


import math
from collections import Counter
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
IN = lambda : input()

def s(a):
	print(''.join(list(map(str, a))))
for i in range(I()):
	a = []
	b = []
	for i in range(9):
		a.append(list(IN()))
	for i in range(9):
		for j in range(9):
			if a[i][j] == '1':
				a[i][j] = '9'
				break
	for i in a:
		print(*i, sep='')


from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())
for _ in range(ii()):
	a = []
	for i in range(9):
		a.append(list(si()))
	a[0][1] = a[0][0]
	a[2][7] = a[2][6]
	a[3][2] = a[3][0]
	a[1][4] = a[1][3]
	a[8][6] = a[8][8]
	a[4][5] = a[4][3]
	a[5][8] = a[5][6]
	a[6][0] = a[6][2]
	a[7][3] = a[7][5]
	for i in range(9):
		x = a[i]
		x = ''.join(x)
		print(x)


t = int(input())
for _ in range(t):
	sudoku = []
	for i in range(9):
		sudoku.append(list(input()))
	print()
	for i in range(9):
		for j in range(9):
			if sudoku[i][j] == '2':
				sudoku[i][j] = '3'
	for row in sudoku:
		for num in row:
			print(num, end='')
		print()


t = int(input())
for _ in range(t):
	grid = []
	for i in range(9):
		row = list(map(int, list(input())))
		grid.append(row)
	points = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for (x, y) in points:
		block = []
		sx = x // 3 * 3
		sy = y // 3 * 3
		for j in range(3):
			for k in range(3):
				block.append(grid[sx + j][sy + k])
		for d in range(1, 10):
			if grid[x][y] != d and d in grid[x] and (d in [grid[j][y] for j in range(9)]) and (d in block):
				grid[x][y] = d
				break
	for i in grid:
		print(''.join([str(j) for j in i]))


from sys import stdin, stdout
grid = []
for i in range(int(stdin.readline())):
	for _ in range(9):
		grid.append(stdin.readline().strip().replace('2', '1'))
for i in grid:
	stdout.write(i + '\n')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	t = I()
	rr = []
	for _ in range(t):
		aa = [[c for c in S()] for _ in range(9)]
		aa[0][0] = aa[0][1]
		aa[1][3] = aa[1][4]
		aa[2][6] = aa[2][7]
		aa[3][1] = aa[3][2]
		aa[4][4] = aa[4][5]
		aa[5][7] = aa[5][8]
		aa[6][2] = aa[6][0]
		aa[7][5] = aa[7][3]
		aa[8][8] = aa[8][6]
		rr.append(JAA(aa, '\n', ''))
	return JA(rr, '\n')
print(main())


t = int(input())
for _ in range(t):
	sud = []
	for i in range(9):
		so = input()
		l = []
		for j in range(9):
			l.append(int(so[j]))
		sud.append(l)
	i = j = 0
	while i < 3:
		sud[i][j] = sud[i][j + 1]
		i += 1
		j += 3
	k = 3
	l = 0
	while k < 6:
		sud[k][l + 1] = sud[k][l]
		k += 1
		l += 3
	m = 6
	n = 0
	while m < 9:
		sud[m][n + 2] = sud[m][n + 1]
		m += 1
		n += 3
	for i in range(9):
		s = ''
		for j in range(9):
			s += str(sud[i][j])
		print(s)


from collections import Counter
for _ in range(int(input())):
	for i in range(9):
		s = list(input())
		s[s.index('2')] = '3'
		print(''.join(s))


def solve(s):
	for (r, c) in [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7)]:
		s[r][c] = s[r][c + 1]
	for (r, c) in [(6, 2), (7, 5), (8, 8)]:
		s[r][c] = s[r][c - 1]
t = int(input())
for _ in range(t):
	sudoku = []
	for _ in range(9):
		sudoku.append(list(map(int, list(input()))))
	solve(sudoku)
	for row in sudoku:
		print(''.join(map(str, row)))


import string
t = int(input())
for i in range(t):
	l = []
	for i in range(9):
		s = input()
		l.append(list(s))
	for i in range(3):
		for j in range(3):
			if l[3 * i + j][3 * j + i] == str(9):
				l[3 * i + j][3 * j + i] = str(1)
			else:
				l[3 * i + j][3 * j + i] = str(9 - int(l[3 * i + j][3 * j + i]))
	for i in range(9):
		print(''.join(l[i]))


from collections import Counter
for _ in range(int(input())):
	l = []
	for i in range(9):
		l.append(input())
	for i in l:
		for j in i:
			if j == '1':
				print(2, end='')
			else:
				print(j, end='')
		print()


b = int(input())
for i in range(b * 9):
	res = ''
	k = input()
	for j in k:
		if j == '1':
			res += '8'
		else:
			res += j
	print(res)


for i in range(int(input())):
	for i in range(9):
		print(input().replace('3', '4'))


for _ in range(int(input())):
	mat = []
	for i in range(9):
		mat.append(list(input()))
	for blocks in range(3):
		j = blocks * 3
		for i in range(blocks, 9, 3):
			if j + 1 < 9:
				mat[i][j] = mat[i][j + 1]
			j += 1
	mat[8][8] = mat[8][0]
	for row in mat:
		print(''.join(row))


t = int(input())
changes = ((0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8))
for case in range(t):
	sudoku = []
	for line in range(9):
		sudoku.append(list(input()))
	for (row, col) in changes:
		if sudoku[row][col] == '1':
			sudoku[row][col] = '2'
		else:
			sudoku[row][col] = '1'
	for row in sudoku:
		print(''.join(row))


from itertools import groupby
t = int(input())

def solve(l):
	ll = []
	for i in range(0, len(l)):
		res = ''
		for j in range(0, len(l[i])):
			if int(l[i][j]) == 1:
				res += str(2)
			else:
				res += str(l[i][j])
		ll.append(res)
	return ll
while t > 0:
	l = []
	for i in range(0, 9):
		s = input()
		l.append([c for c in s])
	res = solve(l)
	for i in res:
		print(i)
	t -= 1


from sys import stdin, stdout
from math import gcd, sqrt, floor, ceil
input = stdin.readline

def list_inp(x):
	return list(map(x, input().split()))

def map_inp(x):
	return map(x, input().split())

def lcm(a, b):
	return a * b / gcd(a, b)
t = int(input())
for _ in range(t):
	arr = []
	for i in range(9):
		arr.append(input().replace('2', '1'))
	for i in range(9):
		print(arr[i])


for _ in range(int(input())):
	arr = [None] * 9
	ans = [None] * 9
	for i in range(9):
		arr[i] = input()
		ans[i] = list(arr[i])
	ones = [None] * 9
	s = set()
	for i in range(9):
		for j in range(9):
			if arr[i][j] == '1':
				if i // 3 * 3 + (i + 1) % 3 not in s:
					ans[i // 3 * 3 + (i + 1) % 3][j] = '1'
					s.add(i // 3 * 3 + (i + 1) % 3)
				elif i // 3 * 3 + (i + 2) % 3 not in s:
					ans[i // 3 * 3 + (i + 2) % 3][j] = '1'
					s.add(i // 3 * 3 + (i + 2) % 3)
	for i in range(9):
		print(''.join(ans[i]))


n = int(input())
s = [[0] * 9 for i in range(9 * n)]
for x in range(9 * n):
	s[x] = list(input())
for x in range(9 * n):
	s[x][s[x].index('9')] = '1'
	print(''.join(s[x]))


t = int(input())
for case in range(t):
	sud = []
	change = [0, 3, 6]
	digit = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
	for i in range(9):
		row = list(input())
		col_set = i // 3
		row_set = change[i % 3]
		tot_set = col_set + row_set
		ofset = 1
		if tot_set == 8:
			ofset -= 1
		c = row[tot_set]
		for d in digit:
			if d != c:
				row[tot_set] = d
				break
		sud.append(''.join(row))
	for r in sud:
		print(r)


t = int(input())
for _ in range(t):
	lst = []
	for i in range(9):
		lst += [list(input().strip())]
	j = 0
	for i in range(3):
		lst[i * 3][i] = '3' if lst[i * 3][i] != '3' else '4'
		lst[i * 3 + 1][i + 3] = '3' if lst[i * 3 + 1][i + 3] != '3' else '4'
		lst[i * 3 + 2][i + 6] = '3' if lst[i * 3 + 2][i + 6] != '3' else '4'
	for i in range(9):
		print(''.join(lst[i]))


for _ in range(int(input())):
	sudoku = []
	for i in range(9):
		sudoku.append([c for c in input()])
	for i in range(3):
		for j in range(3):
			el = sudoku[3 * i + j][3 * j + i]
			sudoku[3 * i + j][3 * j + i] = '1' if el != '1' else '9'
	for i in sudoku:
		print(''.join(i))


from math import *
from copy import *
from heapq import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def solve(L):
	n = len(L)
	l = [[0, 0], [1, 4], [2, 6], [4, 1], [3, 3], [5, 7], [7, 2], [8, 5], [6, 8]]
	for ii in l:
		(i, j) = ii
		curr = L[i][j]
		for k in range(1, 10):
			if curr != str(k):
				L[i][j] = str(k)
				break
	for i in L:
		print(''.join(i))
T = int(input())
for _ in range(T):
	L = []
	for i in range(9):
		l = input()
		L.append(list(l))
	solve(L)


for _ in range(int(input())):
	l = []
	for i in range(9):
		l.append(list(map(int, input())))
	z = [7, 2, 6, 9, 3, 5, 8, 1, 4]
	for i in range(9):
		l[i][z[i] - 1] += 1
		if l[i][z[i] - 1] > 9:
			l[i][z[i] - 1] = 1
	for i in range(9):
		print(''.join([str(i) for i in l[i]]))


from math import *

def main():
	for _ in range(int(input())):
		arr = []
		for i in range(9):
			row = list(map(int, input()))
			arr.append(row)
		c = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
		for i in range(len(c)):
			(x, y) = c[i]
			if arr[x][y] == 9:
				arr[x][y] = 1
			else:
				arr[x][y] += 1
		for i in arr:
			for j in i:
				print(j, end='')
			print()
main()


T = int(input())
for t in range(T):
	arr = []
	for T in range(9):
		arr.append(list(input()))
	temp = int(arr[0][0]) + 1
	if temp == 10:
		temp = 1
	arr[0][0] = str(temp)
	temp = int(arr[1][3]) + 1
	if temp == 10:
		temp = 1
	arr[1][3] = str(temp)
	temp = int(arr[2][6]) + 1
	if temp == 10:
		temp = 1
	arr[2][6] = str(temp)
	temp = int(arr[3][1]) + 1
	if temp == 10:
		temp = 1
	arr[3][1] = str(temp)
	temp = int(arr[4][4]) + 1
	if temp == 10:
		temp = 1
	arr[4][4] = str(temp)
	temp = int(arr[5][7]) + 1
	if temp == 10:
		temp = 1
	arr[5][7] = str(temp)
	temp = int(arr[6][2]) + 1
	if temp == 10:
		temp = 1
	arr[6][2] = str(temp)
	temp = int(arr[7][5]) + 1
	if temp == 10:
		temp = 1
	arr[7][5] = str(temp)
	temp = int(arr[8][8]) + 1
	if temp == 10:
		temp = 1
	arr[8][8] = str(temp)
	for i in range(9):
		arr[i] = ''.join(arr[i])
	for i in range(9):
		print(arr[i])


t = int(input())
list = [[0, 0], [3, 1], [6, 2], [1, 3], [4, 4], [7, 5], [2, 6], [5, 7], [8, 8]]
for _ in range(t):
	arr = [[0 for i in range(9)] for j in range(9)]
	for i in range(9):
		string = input()
		for j in range(9):
			arr[i][j] = int(string[j])
	for x in list:
		if arr[x[0]][x[1]] % 2 == 0:
			arr[x[0]][x[1]] = 1
		else:
			arr[x[0]][x[1]] = 2
	for i in range(9):
		for j in range(9):
			print(arr[i][j], end='')
		print()


from collections import Counter

class Solution:

	def solver(self, matrix):
		targets = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
		for target in targets:
			counter = (matrix[target[0]][target[1]] + 1) % 9
			if counter == 0:
				counter = 1
			matrix[target[0]][target[1]] = counter
		s = []
		for r in matrix:
			s.append(''.join([str(item) for item in r]))
		return '\n'.join(s)

	def solve(self):
		t = int(input())
		for i in range(t):
			matrix = []
			for i in range(9):
				line = input()
				nums = [int(c) for c in line]
				matrix.append(nums)
			print(self.solver(matrix))
Solution().solve()


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().split()))
d = {x: x + 1 if x != 9 else 1 for x in range(1, 10)}
cng = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
for i in range(int(input())):
	inp = []
	for _ in range(9):
		s = input().strip('\n')
		inp.append(list(s))
	for (j, k) in cng:
		inp[j][k] = str(d[int(inp[j][k])])
	out = []
	for _ in range(9):
		out.append(''.join(inp[_]))
	print('\n'.join(out))


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	S = ''
	for _ in range(9):
		a = input()
		S += a
	Query.append(S)
for S in Query:
	print(S.replace('1', '2'))


t = int(input())
for q in range(t):
	sudoku = []
	for x in range(9):
		sudoku.append([int(x) for x in input()])
	if sudoku[0][0] == 9:
		sudoku[0][0] = 1
	else:
		sudoku[0][0] += 1
	if sudoku[3][1] == 9:
		sudoku[3][1] = 1
	else:
		sudoku[3][1] += 1
	if sudoku[6][2] == 9:
		sudoku[6][2] = 1
	else:
		sudoku[6][2] += 1
	if sudoku[1][3] == 9:
		sudoku[1][3] = 1
	else:
		sudoku[1][3] += 1
	if sudoku[4][4] == 9:
		sudoku[4][4] = 1
	else:
		sudoku[4][4] += 1
	if sudoku[7][5] == 9:
		sudoku[7][5] = 1
	else:
		sudoku[7][5] += 1
	if sudoku[2][6] == 9:
		sudoku[2][6] = 1
	else:
		sudoku[2][6] += 1
	if sudoku[5][7] == 9:
		sudoku[5][7] = 1
	else:
		sudoku[5][7] += 1
	if sudoku[8][8] == 9:
		sudoku[8][8] = 1
	else:
		sudoku[8][8] += 1
	line = ''
	for x in sudoku:
		for y in x:
			line += str(y)
		print(line)
		line = ''


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
for _ in range(ii()):
	sudoku = [list(input()) for _ in range(9)]
	for i in range(9):
		for j in range(9):
			if sudoku[i][j] == '2':
				sudoku[i][j] = '1'
	for i in range(9):
		print(*sudoku[i], sep='')


for _ in range(int(input())):
	x = [8, 5, 2]
	n = 9
	for i in range(n):
		n = 9
		A = input()
		if i < 6:
			if x[i % 3] == n - 1:
				A = A[:x[i % 3]] + A[x[i % 3] - 1]
			else:
				A = A[:x[i % 3]] + A[x[i % 3] - 1] + A[x[i % 3] + 1:]
			x[i % 3] -= 1
		elif x[i % 3] == 0:
			A = A[x[i % 3] + 2] + A[1:]
		else:
			A = A[:x[i % 3]] + A[x[i % 3] + 2] + A[x[i % 3] + 1:]
		print(A)


t = int(input())
pos = [(x + y // 3, y + x // 3) for x in range(0, 9, 3) for y in range(0, 9, 3)]
for _ in range(t):
	table = [input() for i in range(9)]
	for i in range(9):
		for j in range(9):
			if (i, j) not in pos:
				print(table[i][j], end='')
			elif table[i][j] == '9':
				print(1, end='')
			else:
				print(int(table[i][j]) + 1, end='')
		print()


for _ in range(int(input())):
	arr = []
	for i in range(9):
		arr.append(list(input()))
	for i in range(9):
		for j in range(9):
			if arr[i][j] == '5':
				arr[i][j] = '6'
	for i in arr:
		print(''.join(i))


t = int(input())
for i in range(t):
	for j in range(3):
		for k in range(3):
			a = input()
			s = []
			for l in a:
				s.append(l)
			if int(s[k * 3 + j]) > 1:
				s[k * 3 + j] = str(int(s[k * 3 + j]) - 1)
			else:
				s[k * 3 + j] = str(int(s[k * 3 + j]) + 1)
			print(''.join(s))


t = int(input())
for _ in range(t):
	sudoku = []
	for itr in range(9):
		sudoku.append(list(str(input())))
	sudoku[0][0] = sudoku[1][0]
	sudoku[1][3] = sudoku[2][3]
	sudoku[2][6] = sudoku[3][6]
	sudoku[3][1] = sudoku[4][1]
	sudoku[4][4] = sudoku[5][4]
	sudoku[5][7] = sudoku[6][7]
	sudoku[6][2] = sudoku[7][2]
	sudoku[7][5] = sudoku[8][5]
	sudoku[8][8] = sudoku[0][8]
	for r in sudoku:
		print(''.join(r))


import sys
for _ in range(int(sys.stdin.readline())):
	for _ in range(9):
		a = sys.stdin.readline().strip()
		print(a.replace('1', '5'))


def f(grid):
	for i in range(9):
		for j in range(9):
			if grid[i][j] == '1':
				grid[i][j] = '2'

def main():
	t = int(input())
	for _ in range(t):
		grid = [[x for x in input()] for __ in range(9)]
		f(grid)
		for row in grid:
			print(''.join(row))
main()


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def box(i, j):
	i = int(i)
	j = int(j)
	a = i // 3
	b = j // 3
	return 3 * a + b
testcases = int(input())
for case in range(testcases):
	puzzle = []
	for i in range(9):
		zax = []
		s = input()
		for j in range(9):
			zax.append(s[j])
		puzzle.append(zax)
	done_i = [False, False, False, False, False, False, False, False, False]
	done_j = [False, False, False, False, False, False, False, False, False]
	done_box = [False, False, False, False, False, False, False, False, False]
	for i in range(9):
		for j in range(9):
			if not done_i[i] and (not done_j[j]) and (not done_box[box(i, j)]):
				val = puzzle[i][j]
				if val == '1':
					replacement = '2'
				else:
					replacement = '1'
				puzzle[i][j] = replacement
				done_i[i] = True
				done_j[j] = True
				done_box[box(i, j)] = True
	for i in range(9):
		print(''.join(puzzle[i]))


from sys import stdin
input = stdin.readline

def A():
	for i in range(int(input())):
		print((int(input()) - 1) // 2)

def B():
	for _ in range(int(input())):
		(n, a, b) = map(int, input().split())
		s = 'abcdefghijklmnopqrstuvwxyz'[0:b] * (n // b + 1)
		print(s[0:n])
	return

def C():
	for _ in range(int(input())):
		n = int(input())
		d = [0] * (n + 1)
		a = list(map(int, input().split()))
		for i in a:
			d[i] += 1
		one = max(d) - 1
		two = len(set(a))
		if one < two:
			two -= 1
			one += 1
		print(min(one, two))
	return

def D():
	for _ in range(int(input())):
		l = [[0 for i in range(9)] for j in range(9)]
		for i in range(9):
			s = input().rstrip()
			for j in range(9):
				l[i][j] = s[j]
		p = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
		for (i, j) in p:
			l[i][j] = str(int(l[i][j]) % 9 + 1)
		for row in l:
			print(''.join(row))
	return
D()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far
from math import *
for _ in range(int(input())):
	li = []
	for i in range(9):
		li.append(input().replace('1', '2'))
	for i in range(9):
		print(li[i])


t = int(input())
ch = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(t):
	a = []
	for i in range(9):
		s = input()
		a.append([int(j) for j in s])
	a[0][0] = a[0][0] % 9 + 1
	a[1][4] = a[1][4] % 9 + 1
	a[2][8] = a[2][8] % 9 + 1
	a[3][3] = a[3][3] % 9 + 1
	a[4][7] = a[4][7] % 9 + 1
	a[5][2] = a[5][2] % 9 + 1
	a[6][6] = a[6][6] % 9 + 1
	a[7][1] = a[7][1] % 9 + 1
	a[8][5] = a[8][5] % 9 + 1
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


q = int(input())
for _ in range(q):
	sudoku = []
	for i in range(9):
		s = str(input())
		sudoku.append(list(s))
	a = [[(0, 0), (1, 4), (2, 8), (3, 1), (4, 5), (5, 6), (6, 2), (7, 3), (8, 7)], [(0, 1), (1, 5), (2, 6), (3, 2), (4, 3), (5, 7), (6, 0), (7, 4), (8, 8)], [(0, 2), (1, 3), (2, 7), (3, 0), (4, 4), (5, 8), (6, 1), (7, 5), (8, 6)]]
	s = set()
	c = -1
	for i in a:
		s = set()
		for j in i:
			s.add(sudoku[j[0]][j[1]])
		for t in range(1, 10):
			if str(t) not in s:
				c = t
		if c != -1:
			for j in i:
				sudoku[j[0]][j[1]] = str(c)
			for j in sudoku:
				ans = ''
				for l in j:
					ans += l
				print(ans)
			break
		else:
			continue


t = int(input())
targets = [0, 4, 8, 3, 1, 7, 6, 5, 2]
for i in range(t):
	for j in range(9):
		line = list(input())
		number = ord(line[targets[j]])
		line[targets[j]] = chr((number - ord('1') + 1) % 9 + ord('1'))
		print(''.join(line))


from sys import stdin, stdout
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()

def pprint(M):
	for row in M:
		print(row)
	print('~~~')

def main():
	T = int(rl())
	for _ in range(T):
		board = []
		for _ in range(9):
			row = [int(x) for x in list(rll()[0])]
			board.append(row)
		sqs = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
		for (r, c) in sqs:
			board[r][c] += 1
			if board[r][c] > 9:
				board[r][c] = 1 + board[r][c] % 10
		ans = [''.join((str(c) for c in r)) for r in board]
		ans = '\n'.join((row for row in ans))
		stdout.write(ans)
		stdout.write('\n')
	stdout.close()
main()


t = int(input())
for _ in range(t):
	a = [[int(i) for i in input()] for j in range(9)]
	for i in range(3):
		for j in range(3):
			a[i * 3 + j][i + 3 * j] = (a[i * 3 + j][i + 3 * j] + 1) % 9 + 1
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


from random import choice

def func(t):
	X = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	for i in range(len(X)):
		if X[i] != int(t):
			break
	return str(X[i])
for _ in range(int(input())):
	A = input()
	B = input()
	C = input()
	D = input()
	E = input()
	F = input()
	G = input()
	H = input()
	I = input()
	A = func(A[0]) + A[1:]
	B = B[0:3] + func(B[3]) + B[4:]
	C = C[0:6] + func(C[6]) + C[7:]
	D = D[0:1] + func(D[1]) + D[2:]
	E = E[0:4] + func(E[4]) + E[5:]
	F = F[0:7] + func(F[7]) + F[8:]
	G = G[0:2] + func(G[2]) + G[3:]
	H = H[0:5] + func(H[5]) + H[6:]
	I = I[0:8] + func(I[8])
	print(A)
	print(B)
	print(C)
	print(D)
	print(E)
	print(F)
	print(G)
	print(H)
	print(I)


for t in range(int(input())):
	m = [list(input()) for i in range(9)]
	for i in range(9):
		j = i * 4 % 9
		m[i][j] = str(int(m[i][j]) % 9 + 1)
		print(''.join(m[i]))


n = int(input())
for i in range(n):
	sts = []
	for j in range(9):
		st = input()
		sts.append(list(st))
	sts[0][0] = sts[0][1]
	sts[1][3] = sts[1][4]
	sts[2][6] = sts[2][7]
	sts[3][1] = sts[3][2]
	sts[4][4] = sts[4][5]
	sts[5][7] = sts[5][8]
	sts[6][2] = sts[6][3]
	sts[7][5] = sts[7][6]
	sts[8][8] = sts[8][7]
	for j in range(9):
		for h in range(9):
			print(sts[j][h], end='')
		print('')


n = int(input())
for i in range(n):
	s = []
	for j in range(9):
		s.append(input().replace('1', '2'))
	for j in s:
		print(j)


t = int(input())
for t1 in range(0, t):
	c = 1
	l = []
	a = 0
	b = 0
	c = 0
	for i in range(0, 9):
		z = input()
		z = list(z)
		if i % 3 == 0:
			index = 6 + a
			if index > 7:
				z[index] = z[6]
			else:
				z[index] = z[index + 1]
			a = a + 1
		elif i % 3 == 1:
			index = 3 + b
			if index > 4:
				z[index] = z[3]
			else:
				z[index] = z[index + 1]
			b = b + 1
		else:
			index = 0 + c
			if index > 1:
				z[index] = z[0]
			else:
				z[index] = z[index + 1]
			c = c + 1
		z = ''.join(z)
		l.append(z)
	for i in range(0, 9):
		print(l[i])


t = int(input())
l = []
for i in range(t):
	for j in range(9):
		o = input()
		l = list(o)
		l[l.index('1')] = '2'
		print(''.join(l))


for _ in range(int(input())):
	su = []
	for i in range(9):
		x = input()
		li = [int(i) for i in x]
		su.append(li)
	for j in range(9):
		if su[j][3 * j % 9 + j // 3] == 9:
			su[j][3 * j % 9 + j // 3] = 2
		else:
			su[j][3 * j % 9 + j // 3] += 1
	for i in range(9):
		for j in range(9):
			print(su[i][j], end='')
		print()


def f(a):
	b = int(a)
	b += 1
	if b == 10:
		b = 1
	return str(b)
T = int(input())
for t in range(T):
	s = []
	for l in range(9):
		line = list(input())
		s.append(line)
	s[0][0] = f(s[0][0])
	s[1][3] = f(s[1][3])
	s[2][6] = f(s[2][6])
	s[3][1] = f(s[3][1])
	s[4][5] = f(s[4][5])
	s[5][8] = f(s[5][8])
	s[8][2] = f(s[8][2])
	s[6][4] = f(s[6][4])
	s[7][7] = f(s[7][7])
	for line in s:
		print(''.join(line))


t = int(input())
for loop in range(t):
	a = []
	for i in range(9):
		A = list(input())
		a.append(A)
	a[0][0] = a[0][1]
	a[3][1] = a[3][2]
	a[6][2] = a[6][1]
	a[1][3] = a[1][4]
	a[4][4] = a[4][5]
	a[7][5] = a[7][4]
	a[2][6] = a[2][7]
	a[5][7] = a[5][8]
	a[8][8] = a[8][7]
	for i in a:
		print(''.join(i))


for _ in range(int(input())):
	l = []
	for __ in range(9):
		l.append(input())
	x = '2' if l[0][0] == '1' else str(int(l[0][0]) - 1)
	l[0] = x + l[0][1:]
	x = '2' if l[1][8] == '1' else str(int(l[1][8]) - 1)
	l[1] = l[1][:8] + x
	x = '2' if l[2][4] == '1' else str(int(l[2][4]) - 1)
	l[2] = l[2][0:4] + x + l[2][5:]
	x = '2' if l[3][3] == '1' else str(int(l[3][3]) - 1)
	l[3] = l[3][0:3] + x + l[3][4:]
	x = '2' if l[4][7] == '1' else str(int(l[4][7]) - 1)
	l[4] = l[4][:7] + x + l[4][8:]
	x = '2' if l[5][2] == '1' else str(int(l[5][2]) - 1)
	l[5] = l[5][:2] + x + l[5][3:]
	x = '2' if l[6][6] == '1' else str(int(l[6][6]) - 1)
	l[6] = l[6][:6] + x + l[6][7:]
	x = '2' if l[7][1] == '1' else str(int(l[7][1]) - 1)
	l[7] = l[7][0] + x + l[7][2:]
	x = '2' if l[8][5] == '1' else str(int(l[8][5]) - 1)
	l[8] = l[8][:5] + x + l[8][6:]
	for i in range(9):
		for j in l[i]:
			print(j, end='')
		print()


import sys
import io, os
for _ in range(int(input())):
	arr = []
	for i in range(9):
		a = input()
		b = a.replace('2', '1')
		arr.append(b)
	for i in arr:
		print(i)


res = []
t = int(input())
for i in range(t):
	x = []
	for n in range(9):
		x.append(input())
	res.append(x)
for x in res:
	for k in x:
		v = k.replace(str(2), str(3))
		print(v)


for _ in range(int(input())):
	t = 0
	for i in range(9):
		l = list(input())
		if i % 3 == 0:
			if l[t] == '9':
				l[t] = '1'
			l[t] = str(9 - int(l[t]))
		elif i % 3 == 1:
			if l[t + 3] == '9':
				l[t + 3] = '1'
			l[t + 3] = str(9 - int(l[t + 3]))
		else:
			if l[t + 6] == '9':
				l[t + 6] = '1'
			l[t + 6] = str(9 - int(l[t + 6]))
			t += 1
		print(''.join(l))


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def debug(S):
	for (j, s) in enumerate(S):
		for (i, e) in enumerate(s):
			print(e, end='')
		print()

def solve():
	S = Scanner.string_list(9)
	S = [list(s) for s in S]
	T = [[0 for _ in range(9)] for _ in range(9)]
	for (i, line) in enumerate(S):
		for (j, c) in enumerate(line):
			if c == '1':
				c = '9'
			T[i][j] = c
	debug(T)

def main():
	T = Scanner.int()
	for _ in range(T):
		solve()
main()


from sys import stdin
input = stdin.readline
for ti in range(int(input().strip())):
	s = []
	for ri in range(9):
		s.append([int(x) for x in list(input().strip())])
	for ri in range(3):
		for ci in range(3):
			s[3 * ri + ci][3 * ci + ri] += 1 if s[3 * ri + ci][3 * ci + ri] < 9 else -1
	ans = []
	for si in s:
		for sj in si:
			ans.append(str(sj))
		print(''.join(ans))
		ans = []


t = int(input())
for i10 in range(t):
	a = [list(map(int, input())) for i in range(9)]
	a[0][0] = (a[0][0] + 1) % 2 + 2
	a[1][3] = (a[1][3] + 1) % 2 + 2
	a[2][6] = (a[2][6] + 1) % 2 + 2
	a[3][1] = (a[3][1] + 1) % 2 + 2
	a[4][4] = (a[4][4] + 1) % 2 + 2
	a[5][7] = (a[5][7] + 1) % 2 + 2
	a[6][2] = (a[6][2] + 1) % 2 + 2
	a[7][5] = (a[7][5] + 1) % 2 + 2
	a[8][8] = (a[8][8] + 1) % 2 + 2
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


for _ in range(int(input())):
	arr = []
	for _ in range(9):
		s = input()
		l = list(s)
		for i in range(len(l)):
			if l[i] == '1':
				l[i] = '2'
		''.join(l)
		print(''.join(l))


TC = int(input())
for _ in range(TC):
	grid = []
	for _ in range(9):
		grid.append([int(num) for num in input()])
	for row in grid:
		for (index, item) in enumerate(row):
			if item == 1:
				row[index] = 2
	for i in range(9):
		print(''.join([str(num) for num in grid[i]]))


from sys import stdin, stdout
from collections import defaultdict, Counter
from functools import lru_cache
from math import gcd, floor, ceil

def ilist():
	return [int(x) for x in stdin.readline().strip().split(' ')]

def iint():
	return int(stdin.readline().strip())

def istr():
	return stdin.readline().strip()
t = iint()
for _x in range(t):
	puz = [list(istr()) for i in range(9)]
	mod = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for (x, y) in mod:
		puz[x][y] = str(int(puz[x][y]) % 9 + 1)
	for x in puz:
		print(''.join(x))


from collections import Counter
t = int(input())
for _ in range(t):
	a = []
	for i in range(9):
		a.append(list(map(int, list(input()))))
	c = 0
	d = 0
	for i in range(3):
		d = 0
		for j in range(3):
			if a[i * 3 + d][j * 3 + c] + 1 == 10:
				a[i * 3 + d][j * 3 + c] = 1
			else:
				a[i * 3 + d][j * 3 + c] = a[i * 3 + d][j * 3 + c] + 1
			d += 1
		c += 1
	for i in range(9):
		s = list(map(str, a[i]))
		print(''.join(s))


T = int(input())
i = 0
while i < T:
	i += 1
	a = [[int(k) for k in input()] for j in range(9)]
	a[0][0] = a[1][1]
	a[3][1] = a[4][1]
	a[6][2] = a[7][1]
	a[1][3] = a[1][4]
	a[4][4] = a[3][4]
	a[7][5] = a[7][4]
	a[2][6] = a[1][7]
	a[5][7] = a[4][7]
	a[8][8] = a[7][7]
	for rows in a:
		print(''.join((str(i) for i in rows)))


from collections import Counter

def solve(grid):
	ans = []
	n = 9
	for i in range(n):
		if i == 0:
			grid[i][0] = grid[i][1]
		elif i == 1:
			grid[i][3] = grid[i][4]
		elif i == 2:
			grid[i][6] = grid[i][7]
		elif i == 3:
			grid[i][1] = grid[i][2]
		elif i == 4:
			grid[i][4] = grid[i][5]
		elif i == 5:
			grid[i][7] = grid[i][8]
		elif i == 6:
			grid[i][2] = grid[i][0]
		elif i == 7:
			grid[i][5] = grid[i][3]
		else:
			grid[i][8] = grid[i][6]
	for (i, g) in enumerate(grid):
		print(''.join(g))
	return ans

def main():
	t = int(input())
	(i, n) = (1, 9)
	while i <= t:
		sudoko = []
		for j in range(n):
			sudoko.append(list(input()))
		solve(sudoko)
		i += 1
main()


testCases = int(input())
for _ in range(testCases):
	sudoku = []
	for i1 in range(9):
		temp = list(map(int, list(input())))
		sudoku.append(temp)
	for i in range(3):
		for i1 in range(3):
			sudoku[i * 3 + i1][i1 * 3 + i]
			if i1 == 0:
				sudoku[i * 3 + i1][i1 * 3 + i] = sudoku[i * 3 + i1 + 1][i1 * 3 + i]
			elif i1 == 1:
				sudoku[i * 3 + i1][i1 * 3 + i] = sudoku[i * 3 + i1 + 1][i1 * 3 + i]
			else:
				sudoku[i * 3 + i1][i1 * 3 + i] = sudoku[i * 3 + i1 - 1][i1 * 3 + i]
			print(''.join([str(elem) for elem in sudoku[i * 3 + i1]]))


q = int(input())
ans = [[] for y in range(12)]
while q > 0:
	q -= 1
	temp = 1
	cnt = 1
	for i in range(1, 10):
		ans[i] = input()
		ans[i] = list(ans[i])
		ans[i].insert(0, 0)
		for j in range(1, 10):
			ans[i][j] = int(ans[i][j])
		ans[i][cnt] += 1
		if ans[i][cnt] > 9:
			ans[i][cnt] = 1
		cnt += 3
		if cnt > 9:
			temp += 1
			cnt = temp
	for i in range(1, 10):
		for j in range(1, 10):
			print(ans[i][j], end='')
		print()
	print()


t = int(input())
sudoku = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
for tt in range(t):
	for i in range(9):
		temp = input()
		for j in range(9):
			sudoku[i][j] = int(temp[j])
	sudoku[0][0] = sudoku[0][0] % 9 + 1
	sudoku[3][1] = sudoku[3][1] % 9 + 1
	sudoku[6][2] = sudoku[6][2] % 9 + 1
	sudoku[1][3] = sudoku[1][3] % 9 + 1
	sudoku[4][4] = sudoku[4][4] % 9 + 1
	sudoku[7][5] = sudoku[7][5] % 9 + 1
	sudoku[2][6] = sudoku[2][6] % 9 + 1
	sudoku[5][7] = sudoku[5][7] % 9 + 1
	sudoku[8][8] = sudoku[8][8] % 9 + 1
	for i in range(9):
		for j in range(9):
			print(sudoku[i][j], end='')
		print()


for _ in range(int(input())):
	s1 = str(input())
	l1 = list(s1)
	l1[0] = l1[1]
	s2 = str(input())
	l2 = list(s2)
	l2[3] = l2[4]
	s3 = str(input())
	l3 = list(s3)
	l3[6] = l3[7]
	s4 = str(input())
	l4 = list(s4)
	l4[1] = l4[2]
	s5 = str(input())
	l5 = list(s5)
	l5[4] = l5[5]
	s6 = str(input())
	l6 = list(s6)
	l6[7] = l6[8]
	s7 = str(input())
	l7 = list(s7)
	l7[2] = l7[0]
	s8 = str(input())
	l8 = list(s8)
	l8[5] = l8[3]
	s9 = str(input())
	l9 = list(s9)
	l9[8] = l9[6]
	for i in range(9):
		print(l1[i], end='')
	print()
	for i in range(9):
		print(l2[i], end='')
	print()
	for i in range(9):
		print(l3[i], end='')
	print()
	for i in range(9):
		print(l4[i], end='')
	print()
	for i in range(9):
		print(l5[i], end='')
	print()
	for i in range(9):
		print(l6[i], end='')
	print()
	for i in range(9):
		print(l7[i], end='')
	print()
	for i in range(9):
		print(l8[i], end='')
	print()
	for i in range(9):
		print(l9[i], end='')
	print()


t = int(input())
for u in range(t):
	l = []
	for i in range(9):
		l.append(list(input()))
	for i in range(9):
		for j in range(9):
			if l[i][j] == '2':
				l[i][j] = '1'
	for i in range(9):
		s = ''
		for j in range(9):
			s = s + l[i][j]
		print(s)


from sys import stdin

def solve():
	A = []
	for _ in range(9):
		k = list(str(input()))
		A.append(k)
	i = 0
	for j in range(0, 9, 3):
		if A[i][j] == '1':
			A[i][j] = '2'
		else:
			A[i][j] = '1'
		i += 1
	i = 3
	for j in range(1, 9, 3):
		if A[i][j] == '1':
			A[i][j] = '2'
		else:
			A[i][j] = '1'
		i += 1
	i = 6
	for j in range(2, 9, 3):
		if A[i][j] == '1':
			A[i][j] = '2'
		else:
			A[i][j] = '1'
		i += 1
	for i in A:
		for j in i:
			print(j, end='')
		print('\r')
t = int(input())
for i in range(t):
	solve()


t = int(input())
for w in range(t):
	l = []
	for i in range(9):
		l.append(list(input()))
	l1 = [0, 1, 2, 3, 4, 5, 6, 7, 8]
	l2 = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		if l[l1[i]][l2[i]] != '9':
			l[l1[i]][l2[i]] = str(int(l[l1[i]][l2[i]]) + 1)
		else:
			l[l1[i]][l2[i]] = '1'
	for i in range(9):
		print(''.join(l[i]))


T = int(input())
for I in range(0, T):
	A = []
	for J in range(0, 9):
		A.append(list(input()))
	B = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for J in range(0, 9):
		if J != 8:
			A[J][B[J]] = A[J][B[J] + 1]
		else:
			A[J][B[J]] = A[J][B[J] - 1]
		print(''.join(A[J]))


for q in range(int(input())):
	ans = []
	for i in range(9):
		s = input()
		add = []
		for h in s:
			add.append(int(h))
		ans.append(add)
	ans[0][0] = ans[0][0] % 9 + 1
	ans[1][3] = ans[1][3] % 9 + 1
	ans[2][6] = ans[2][6] % 9 + 1
	ans[3][1] = ans[3][1] % 9 + 1
	ans[4][4] = ans[4][4] % 9 + 1
	ans[5][7] = ans[5][7] % 9 + 1
	ans[6][2] = ans[6][2] % 9 + 1
	ans[7][5] = ans[7][5] % 9 + 1
	ans[8][8] = ans[8][8] % 9 + 1
	for i in ans:
		for j in i:
			print(j, end='')
		print()


import sys
input = sys.stdin.readline
t = int(input())
ans = []
for _ in range(t):
	for i in (0, 3, 6, 1, 4, 7, 2, 5, 8):
		l = list(input()[:-1])
		l[i] = str((int(l[i]) + 1) % 10 or 1)
		ans.append(''.join(l))
print('\n'.join(ans))


n = int(input())
for i in range(n):
	for j in range(9):
		x = list((x for x in input()))
		for k in range(9):
			if x[k] == '2':
				x[k] = '1'
				break
		print(''.join(x))


import sys
import math

def change(s, j, ch):
	return s.replace(s[j], ch)
t = int(input())
for i in range(t):
	s = []
	for j in range(9):
		s.append(input())
	for j in range(8):
		s[j] = change(s[j], j % 3 * 3 + j // 3, s[j // 3 * 3 + 2][j % 3 * 3 + 2])
	s[8] = change(s[8], 8, s[8][7])
	for j in range(9):
		print(s[j])


t = int(input())
while t != 0:
	list1 = list()
	for i in range(9):
		n = input()
		list1.append(list(n))
	for i in range(9):
		for j in range(9):
			list1[i][j] = int(list1[i][j])
	p = [list1[0][0], list1[1][3], list1[2][6], list1[3][1], list1[4][4], list1[5][7], list1[6][2], list1[7][5], list1[8][8]]
	if list1[0][0] == 9:
		list1[0][0] = 8
	else:
		list1[0][0] += 1
	if list1[1][3] == 9:
		list1[1][3] = 8
	else:
		list1[1][3] += 1
	if list1[2][6] == 9:
		list1[2][6] = 8
	else:
		list1[2][6] += 1
	if list1[3][1] == 9:
		list1[3][1] = 8
	else:
		list1[3][1] += 1
	if list1[4][4] == 9:
		list1[4][4] = 8
	else:
		list1[4][4] += 1
	if list1[5][7] == 9:
		list1[5][7] = 8
	else:
		list1[5][7] += 1
	if list1[6][2] == 9:
		list1[6][2] = 8
	else:
		list1[6][2] += 1
	if list1[7][5] == 9:
		list1[7][5] = 8
	else:
		list1[7][5] += 1
	if list1[8][8] == 9:
		list1[8][8] = 8
	else:
		list1[8][8] += 1
	for i in range(9):
		for j in range(9):
			print(list1[i][j], end='')
		print()
	t -= 1


n = int(input())
sud = []
for i in range(n):
	sud.append([])
	for j in range(9):
		sud[i].append(list(input()))
for s in sud:
	inc = 0
	for i in range(9):
		s[i][inc] = str(int(s[i][inc]) - 1)
		if s[i][inc] == '0':
			s[i][inc] = '9'
		inc += 3
		if inc >= 9:
			inc = inc - 8
	for row in s:
		print(''.join(row))


t = int(input())
a = 1
for i in range(t * 9):
	b = input()
	print(b.replace('1', '7'))
	a = a + 1


for _ in range(int(input())):
	for i in range(9):
		s = input()
		lst = []
		for i in s:
			lst.append(i)
		for i in range(len(lst)):
			if lst[i] == '1':
				lst[i] = '2'
		print(''.join(lst))


t = int(input())

def next(n):
	if n == 9:
		return '1'
	else:
		return str(n + 1)
for i in range(t):
	for i in range(9):
		line = input()
		if i == 0:
			print(next(int(line[0])) + line[1:])
		elif i == 8:
			print(line[0:8] + next(int(line[8])))
		elif i == 1:
			print(line[0:3] + next(int(line[3])) + line[4:])
		elif i == 2:
			print(line[0:6] + next(int(line[6])) + line[7:])
		elif i == 3:
			print(line[0:1] + next(int(line[1])) + line[2:])
		elif i == 4:
			print(line[0:4] + next(int(line[4])) + line[5:])
		elif i == 5:
			print(line[0:7] + next(int(line[7])) + line[8:])
		elif i == 6:
			print(line[0:2] + next(int(line[2])) + line[3:])
		elif i == 7:
			print(line[0:5] + next(int(line[5])) + line[6:])


t = int(input())
for _ in range(t):
	cur = 1
	pos = {}
	for i in range(9):
		x = input()
		ans = []
		for k in x:
			ans.append(int(k))
		for x in ans:
			if x == 2:
				print('1', end='')
			else:
				print(x, end='')
		print()


t = int(input())
r = [i for i in range(9)]
c = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for case_num in range(t):
	a = []
	for i in range(9):
		row = input()
		tmp = []
		for char in row:
			tmp.append(int(char))
		a.append(tmp)
	for i in range(9):
		m = 1 + a[r[i]][c[i]]
		if m > 9:
			m = 1
		a[r[i]][c[i]] = m
	for i in range(9):
		print(''.join(map(str, a[i])))


t = int(input())
while t:
	ls = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		s = input()
		s = [int(s[j]) for j in range(9)]
		if s[ls[i]] == 1:
			s[ls[i]] = 2
		else:
			s[ls[i]] = 1
		print(''.join((str(x) for x in s)))
	t -= 1


for _ in range(int(input())):
	lis = []
	has = [i for i in range(10)]
	for i in range(9):
		a = list(input())
		l = []
		for j in a:
			l.append(int(j))
		lis.append(l)
	c = -1
	for j in range(0, 9, 3):
		c += 1
		for k in range(j, j + 3, 1):
			i = k % 3 * 3 + c
			if lis[i][k] == 1:
				lis[i][k] = 2
			else:
				lis[i][k] = 1
	for i in lis:
		print(*i, sep='')


import sys
input = sys.stdin.readline

def S():
	return input()

def I():
	return int(S())

def M():
	return map(int, S().split())

def L():
	return list(M())
t = int(input())
for i in range(t):
	sudoku = []
	for i in range(9):
		row = list(S())
		sudoku.append(row)
	for i in range(9):
		for j in range(9):
			if sudoku[i][j] == '2':
				sudoku[i][j] = '1'
	ans = ''
	for i in range(9):
		ans += ''.join(sudoku[i])
	print(ans)


test = int(input())

def solve():
	r = []
	for x in range(9):
		s = input()
		m = s.replace('1', '2')
		r.append(m)
	for y in r:
		print(y)
for x in range(test):
	solve()


t = int(input())
for i in range(t):
	s = []
	for j in range(9):
		t = []
		string = input()
		for k in range(9):
			t.append(int(string[k]))
		s.append(t)
	s[0][0] = s[1][0]
	s[3][1] = s[4][1]
	s[6][2] = s[7][2]
	s[1][3] = s[2][3]
	s[4][4] = s[5][4]
	s[7][5] = s[8][5]
	s[2][6] = s[3][6]
	s[5][7] = s[6][7]
	s[8][8] = s[7][8]
	for a in range(9):
		for b in range(9):
			print(s[a][b], end='')
		print()


def solve():
	grid = []
	for _ in range(9):
		row = input()
		row = row.replace('9', '1')
		grid.append(row)
	for row in grid:
		print(row)
T = int(input())
for t in range(T):
	solve()


for i1 in range(int(input())):
	l1 = []
	for j in range(9):
		l1.append(list(input()))
	l1[8][0] = l1[0][0]
	l1[5][1] = l1[0][1]
	l1[2][2] = l1[0][2]
	l1[7][3] = l1[0][3]
	l1[4][4] = l1[0][4]
	l1[1][5] = l1[0][5]
	l1[6][6] = l1[0][6]
	l1[3][7] = l1[0][7]
	l1[0][8] = l1[8][8]
	print()
	for i in l1:
		for j in i:
			print(j, end='')
		print()


T = int(input())
for test in range(T):
	sudoku = []
	for row in range(9):
		sudoku.append([int(chr) for chr in input()])
	for colblock in range(3):
		for block in range(3):
			for r in range(3):
				for c in range(3):
					if sudoku[block * 3 + r][colblock * 3 + c] == 1:
						cell = (r, c)
						break
			indx = (cell[1] + 1) % 3
			sudoku[block * 3 + cell[0]][colblock * 3 + indx] = 1
	for row in sudoku:
		for ind in row:
			print(ind, end='')
		print()


import sys
t = int(sys.stdin.readline())
yxs = [(0, 0), (1, 4), (2, 8), (3, 1), (4, 3), (5, 7), (6, 2), (7, 5), (8, 6)]
for _ in range(t):
	arr = [list(map(int, list(sys.stdin.readline().strip()))) for _ in range(9)]
	for (y, x) in yxs:
		if arr[y][x] >= 1 and arr[y][x] < 9:
			arr[y][x] += 1
		elif arr[y][x] == 9:
			arr[y][x] -= 1
	for j in arr:
		print(''.join(list(map(str, j))))


test_case = int(input())
for i in range(test_case):
	my_list = []
	for j in range(9):
		inp = [i for i in input()]
		my_list.append(inp)
	for k in range(3):
		for l in range(3):
			my_list[k + 3 * l][k * 3 + l] = '9' if my_list[k + 3 * l][k * 3 + l] != '9' else '8'
	for m in my_list:
		print(''.join(m))


t = int(input())
for i in range(t):
	liste = []
	for j in range(1, 10):
		s = input()
		liste.append(s)
	for j in range(0, 9):
		s = list(liste[j])
		for k in range(9):
			if s[k] == '1':
				s[k] = '2'
				break
		liste[j] = ''.join(s)
		print(liste[j])


t = int(input())
for i in range(t):
	arr = []
	for k in range(9):
		ar = list(input())
		arr.append(ar)
	trans = [['0'] * 9 for c in range(9)]
	for x in range(9):
		for y in range(9):
			trans[x][y] = arr[x][y]
	for i in range(9):
		p1 = arr[i].index('2')
		trans[i][p1] = '1'
	for k in range(9):
		print(''.join(trans[k]))


for t in range(int(input())):
	ans = []
	for i in range(9):
		ans.append(input().replace('6', '9'))
	for i in ans:
		print(i)


t = int(input(''))
for _ in range(t):
	for i in range(9):
		x = list(input(''))
		for j in range(len(x)):
			if x[j] == '1':
				x[j] = '2'
		print(''.join(x))


def solver(s):
	t = s.replace('2', '1')
	return t
for _ in range(int(input())):
	for i in range(9):
		a = input()
		print(solver(a))


t = int(input())
for _ in range(t):
	S = [input() for _ in range(9)]
	for i in range(9):
		for j in range(9):
			if S[i][j] == '1':
				print('2', end='')
			else:
				print(S[i][j], end='')
		print()


t = int(input())
for i in range(t):
	for j in range(9):
		s = input()
		print(s.replace('8', '9'))


t = int(input())
for _ in range(t):
	A = [1, 4, 7, 2, 5, 8, 3, 6, 9]
	for j in range(9):
		i = A[j] - 1
		s = input()
		print(s[:i] + str(max((int(s[i]) + 1) % 10, 1)) + s[i + 1:])


T = int(input())
for t in range(T):
	lst = []
	for i in range(9):
		s = input()
		tmp = []
		for j in s:
			tmp.append(int(j))
		lst.append(tmp)
	indices = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for ind in indices:
		(a, b) = ind
		if lst[a][b] == 9:
			lst[a][b] = 1
		else:
			lst[a][b] += 1
	for i in lst:
		for j in i:
			print(j, end='')
		print('\n', end='')


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def ch(s):
	res = '1' if int(s) == 9 else str(int(s) + 1)
	return res
for _ in range(inp()):
	S = []
	for _ in range(9):
		s = list(sys.stdin.readline())
		s = s[:9]
		S.append(s)
	d = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		j = d[i]
		S[i][j] = ch(S[i][j])
	for x in S:
		print(''.join(x))


t = int(input())
for tt in range(t):
	board = [list(input()) for _ in range(9)]
	pos = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
	for i in pos:
		new_pos = int(board[i[0]][i[1]]) + 1
		if new_pos > 9:
			new_pos = 1
		board[i[0]][i[1]] = str(new_pos)
	for row in board:
		print(''.join(row))


for i in range(int(input())):
	l = []
	l1 = ['0'] * 9
	for j in range(9):
		l.append(str(input()))
		l1[j] = l[j].replace('1', '2')
	for j in range(9):
		print(l1[j])


def change(c):
	if c == '9':
		return '1'
	return chr(ord(c) + 1)
t = int(input())
for _ in range(t):
	i = 0
	for __ in range(9):
		s = list(input())
		s[i] = change(s[i])
		print(''.join(s))
		if i < 6:
			i += 3
		else:
			i -= 5


from sys import stdin, stdout
t = int(stdin.readline())
while t > 0:
	for i in range(9):
		a = input().replace('3', '1')
		print(a)
	t -= 1


def main():
	import sys
	input = sys.stdin.readline
	for __ in [0] * int(input()):
		S = [input()[:-1].replace('1', '2') for _ in [0] * 9]
		for s in S:
			print(s)
main()


for t in range(int(input())):
	s = []
	d = {}
	for i in range(9):
		c = input()
		l = list(c)
		s.append(l)
	x = 0
	y = 0
	for i in range(9):
		if y == 9:
			y = 1
		if y == 10:
			y = 2
		ele = int(s[x][y])
		if ele == 9:
			ele = 1
		else:
			ele += 1
		s[x][y] = str(ele)
		x += 1
		y += 3
	for i in range(9):
		print(''.join(s[i]))


t = int(input())
for q in range(0, t):
	s = []
	for i in range(0, 9):
		s1 = input()
		arr = []
		for j in range(0, 9):
			arr.append(s1[j])
		s.append(arr)
	a = [[8, 0], [5, 1], [2, 2], [7, 3], [4, 4], [1, 5], [6, 6], [3, 7], [0, 8]]
	for i in range(0, len(a)):
		if s[a[i][0]][a[i][1]] != '1':
			s[a[i][0]][a[i][1]] = '1'
		else:
			s[a[i][0]][a[i][1]] = '2'
	for i in range(0, 9):
		ans = ''
		for j in range(0, 9):
			ans += s[i][j]
		print(ans)


t = int(input())
for i in range(t):
	lines = []
	for i in range(9):
		temp = input()
		lines.append(temp.replace('1', '2'))
	for i in lines:
		print(i)


n = int(input())
for i in range(n):
	for j in range(9):
		a = input()
		a = a.replace('1', '2')
		print(a)


from bisect import bisect_left as lower_bound, bisect_right as upper_bound
from sys import stdin, stdout
from collections import defaultdict

def solve(arr, n):
	pass

def main():
	t = int(input())
	for _ in range(t):
		n = 9
		mat = [input() for _ in range(n)]
		ma = {0: 0, 3: 1, 6: 2, 1: 4, 4: 5, 7: 3, 2: 8, 5: 6, 8: 7}
		for i in range(n):
			for j in range(n):
				if j == ma[i]:
					num = (int(mat[i][j]) + 1) % 9
					if not num:
						num = 9
					mat[i] = mat[i][:j] + str(num) + mat[i][j + 1:]
		for i in range(n):
			print(mat[i])
main()


t = int(input())
for k in range(t):
	a = []
	for i in range(9):
		a.append(' '.join(input()).split())
	for i in a:
		i[i.index('1')] = '2'
	for i in a:
		s = ''
		for j in i:
			s += j
		print(s)


import sys
import heapq
import math

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

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

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

def YES(flag):
	if flag:
		return 'YES'
	return 'NO'

def main():
	q = [[0, 0], [1, 4], [2, 7], [3, 3], [4, 1], [5, 6], [6, 2], [7, 5], [8, 8]]
	w = [str(i) for i in range(1, 10)]
	e = []
	for i in range(9):
		e.append(list(input()))
	for i in q:
		(x, y) = i
		if e[x][y] != '1':
			e[x][y] = '1'
		else:
			e[x][y] = '9'
	for i in range(9):
		print(''.join(e[i]))
for i in range(iinput()):
	main()


for x in range(int(input())):
	sud = []
	for i in range(9):
		sud.append(input())
	for i in range(9):
		if sud[i][i % 3 * 3 + int(i / 3)] == '9':
			temp = list(sud[i])
			temp[i % 3 * 3 + int(i / 3)] = '1'
			sud[i] = temp
		else:
			temp = list(sud[i])
			temp[i % 3 * 3 + int(i / 3)] = str(int(sud[i][i % 3 * 3 + int(i / 3)]) + 1)
			sud[i] = temp
	for i in range(9):
		print(''.join(sud[i]))


def valid(board, next_pos, value):
	row = board[next_pos[0]]
	col = [row[next_pos[1]] for row in board]

def solve(board):
	next_pos = find_next(board)
	if not next_pos:
		return True
	original_value = board[next_pos[0]][next_pos[1]]
	for value in range(1, 9 + 1):
		if valid(board, next_pos, value):
			board[next_pos[0]][next_pos[1]] = value
			if solve(board):
				return True
			board[next_pos[0]][next_pos[1]] = original_value
	return False
T = int(input())
results = []
for case in range(T):
	board = []
	for i in range(9):
		row = [int(i) for i in input()]
		board.append(row)
	pos = [[i, i // 3 + i % 3 * 3] for i in range(9)]
	for p in pos:
		board[p[0]][p[1]] = board[p[0]][p[1]] % 9 + 1
	results.append(board)
for result in results:
	for row in result:
		print(''.join([str(i) for i in row]))


t = int(input())
indx = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
for _ in range(t):
	a = []
	for i in range(9):
		lst = [int(x) for x in input()]
		a.append(lst)
	for i in range(len(indx)):
		a[indx[i][0]][indx[i][1]] += 1
		a[indx[i][0]][indx[i][1]] %= 9
		if a[indx[i][0]][indx[i][1]] == 0:
			a[indx[i][0]][indx[i][1]] += 9
	for i in range(9):
		strr = ''
		for j in range(9):
			strr += str(a[i][j])
		print(strr)


kl = int(input())
for l in range(kl):
	a = ['' for i in range(9)]
	for i in range(9):
		a[i] = list(input())
	if a[0][0] == '1':
		a[0][0] = '2'
	else:
		a[0][0] = '1'
	if a[1][3] == '1':
		a[1][3] = '2'
	else:
		a[1][3] = '1'
	if a[2][6] == '1':
		a[2][6] = '2'
	else:
		a[2][6] = '1'
	if a[3][1] == '1':
		a[3][1] = '2'
	else:
		a[3][1] = '1'
	if a[4][4] == '1':
		a[4][4] = '2'
	else:
		a[4][4] = '1'
	if a[5][7] == '1':
		a[5][7] = '2'
	else:
		a[5][7] = '1'
	if a[6][2] == '1':
		a[6][2] = '2'
	else:
		a[6][2] = '1'
	if a[7][5] == '1':
		a[7][5] = '2'
	else:
		a[7][5] = '1'
	if a[8][8] == '1':
		a[8][8] = '2'
	else:
		a[8][8] = '1'
	for i in range(9):
		for j in range(9):
			print(str(a[i][j]), end='')
		print()


def main():
	cc = int(input())
	for i in range(cc):
		table = []
		for i in range(3):
			for j in range(3):
				row = input()
				row = list(row)
				if row[i + j * 3] == '1':
					num = '2'
				else:
					num = '1'
				row[i + j * 3] = num
				print(''.join(row))
main()


for T in range(int(input())):
	for i in range(9):
		lis = list(input())
		if int(lis[3 * i % 9 + i // 3]) < 9:
			lis[3 * i % 9 + i // 3] = str(int(lis[3 * i % 9 + i // 3]) + 1)
		else:
			lis[3 * i % 9 + i // 3] = '1'
		print(''.join(lis))


for t in range(int(input())):
	c = 0
	for i in range(1, 10):
		st = input()
		newst = st[0:c] + str(int(st[c]) % 9 + 1) + st[c + 1:9]
		print(newst)
		if i % 3 == 0:
			c = c % 3 + 1
		else:
			c = c + 3


from sys import stdin, stdout
import string
T = int(stdin.readline())
for i in range(T):
	for i in range(9):
		line = stdin.readline()
		line = line.replace('1', '2')
		stdout.write(line)


for _ in range(int(input())):
	l = []
	for t in range(9):
		k = list(map(int, input()))
		l.append(k)
	l[0][0] = l[0][1]
	l[1][3] = l[1][4]
	l[2][6] = l[2][7]
	l[3][1] = l[3][2]
	l[4][4] = l[4][5]
	l[5][7] = l[5][8]
	l[6][2] = l[6][1]
	l[7][5] = l[7][4]
	l[8][8] = l[8][7]
	for t in l:
		print(*t, sep='')


for _ in range(int(input())):
	List = []
	it = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		scan = input()
		feed = [x for x in scan]
		List.append(feed)
	nums = [str(i) for i in range(1, 10)]
	for (j, i) in zip(range(9), it):
		for x in nums:
			if x != List[j][i]:
				List[j][i] = x
				break
	for x in List:
		for a in x:
			print(a, end='')
		print()


for _ in range(int(input())):
	li = []
	for i in range(9):
		li.append(input().replace('1', '2'))
	print(*li, sep='\n')


t = int(input())
for i in range(0, t, 1):
	list1 = []
	for i in range(0, 9, 1):
		m = input()
		list1.append(m)
	p = 0
	for i in range(0, 3, 1):
		z = list1[i][p]
		list1[i] = list1[i][0:p + 1] + z + list1[i][p + 2:]
		p = p + 3
	p = 1
	for i in range(3, 6, 1):
		z = list1[i][p]
		list1[i] = list1[i][0:p + 1] + z + list1[i][p + 2:]
		p = p + 3
	p = 1
	for i in range(6, 9, 1):
		z = list1[i][p]
		list1[i] = list1[i][0:p - 1] + z + list1[i][p:]
		p = p + 3
	for i in range(0, 9, 1):
		for j in range(0, 9, 1):
			print(list1[i][j], end='')
		print()


for _ in range(int(input())):
	x = 0
	for i in range(9):
		a = input()
		a = list(a)
		if a[x] != '5':
			a[x] = '5'
		else:
			a[x] = '6'
		print(*a, sep='')
		if x >= 6:
			x = (x + 3) % 9 + 1
		else:
			x = x + 3


for _ in range(int(input())):
	a = []
	for i in range(9):
		a.append(list(map(str, input())))
	for i in range(3):
		for r in range(3):
			if a[i * 3 + r][r * 3 + i] == '1':
				a[i * 3 + r][r * 3 + i] = '9'
			else:
				a[i * 3 + r][r * 3 + i] = '1'
	for z in range(9):
		print(''.join(a[z]))


t = int(input())
for i in range(t):
	for k in range(9):
		s = input()
		l = list(s)
		for j in range(9):
			if l[j] == '2':
				print(1, end='')
			else:
				print(l[j], end='')
		print()


for i in range(int(input())):
	s1 = str(input())
	s2 = str(input())
	s3 = str(input())
	s4 = str(input())
	s5 = str(input())
	s6 = str(input())
	s7 = str(input())
	s8 = str(input())
	s9 = str(input())
	print(s1[1] + s1[1:])
	print(s2[0:4] + s2[3] + s2[5:])
	print(s3[0:8] + s3[7])
	print(s4[0] + s4[2] + s4[2] + s4[3:])
	print(s5[0:5] + s5[4] + s5[6:])
	print(s6[0:6] + s6[7] + s6[7:])
	print(s7[0:2] + s7[1] + s7[3:])
	print(s8[0:3] + s8[4] + s8[4:])
	print(s9[0:7] + s9[8] + s9[8])


for _ in range(int(input())):
	An = []
	for i in range(9):
		Any = input()
		Any = list(Any)
		An.append(Any)
	i = 0
	while i < 3:
		j = 1
		while j < 9:
			An[i][j - 1] = An[i][j]
			j += 3
			i += 1
	i = 3
	while i < 6:
		j = 2
		while j < 9:
			An[i][j - 1] = An[i][j]
			i += 1
			j += 3
	i = 6
	while i < 9:
		j = 2
		while j < 9:
			An[i][j] = An[i][j - 2]
			j += 3
			i += 1
	for i in range(9):
		for j in range(9):
			print(An[i][j], end='')
		print()


for _ in range(int(input())):
	for i in range(9):
		l = input()
		l = l.replace('4', '5')
		print(l)


def anti_sudoku(sudoku):
	sudoku[0][0] = sudoku[0][1]
	sudoku[1][3] = sudoku[1][4]
	sudoku[2][6] = sudoku[2][7]
	sudoku[3][1] = sudoku[3][2]
	sudoku[4][4] = sudoku[4][5]
	sudoku[5][7] = sudoku[5][8]
	sudoku[6][2] = sudoku[6][3]
	sudoku[7][5] = sudoku[7][6]
	sudoku[8][8] = sudoku[8][7]
	return sudoku

def print_sudoku(sudoku):
	for i in range(9):
		print(''.join(list(map(lambda x: str(x), sudoku[i]))))
t = int(input())
for t_ in range(t):
	outer_a = []
	for i in range(9):
		a = input()
		inner_a = []
		for j in range(9):
			inner_a.append(int(a[j]))
		outer_a.append(inner_a)
	anti_sudok = anti_sudoku(outer_a)
	print_sudoku(anti_sudok)


for u in range(int(input())):
	l = []
	for i in range(9):
		s = input()
		s = s.replace('1', '9')
		l.append(s)
	for i in range(9):
		print(l[i])


for _ in range(int(input())):
	mat = []
	for i in range(9):
		mat.append(list(input()))
	target = 0
	count = 0
	flag = False
	for i in range(9):
		flag = True
		for j in range(9):
			if target == j and flag:
				if mat[i][j] == '1':
					print(2, end='')
				else:
					print(1, end='')
				target += 3
				if target >= 9:
					count += 1
					target = count
				flag = False
			else:
				print(mat[i][j], end='')
		print()


for _ in range(int(input())):
	sud = []
	for i in range(9):
		sud.append(list(map(int, list(input()))))
	for i in range(3):
		j = 3 * i
		for k in range(3):
			sud[j + k][i + 3 * k] = sud[j + k][i + 3 * k] - 1
			if sud[j + k][i + 3 * k] == 0:
				sud[j + k][i + 3 * k] = 9
	for i in range(9):
		for j in range(9):
			print(sud[i][j], end='')
		print('')


n = 9
k = range(n)
t = int(input())
for _ in range(t):
	a = [0 for i in k]
	for i in k:
		s = input()
		s = s.replace('1', '2')
		a[i] = s
	for i in k:
		print(a[i])


for _ in range(int(input())):
	list1 = []
	for i in range(9):
		str1 = list(input())
		str1 = list(map(int, str1))
		list1.append(str1)
	checkvar = 0
	for i in range(len(list1)):
		if i == 0:
			checkvar = 0
		elif i == 3:
			checkvar = 1
		elif i == 6:
			checkvar = 2
		if i != len(list1) - 1:
			for j in range(len(list1[i])):
				if j == checkvar:
					list1[i][j] = list1[i][j + 1]
					checkvar += 3
					flag = 1
					break
		else:
			for j in range(len(list1[i])):
				if j == checkvar:
					list1[i][j] = list1[i][j - 1]
					checkvar += 3
					flag = 1
					break
	for i in range(len(list1)):
		for j in range(len(list1[i])):
			print(list1[i][j], end='')
		print()


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = 9
	a = []
	for _ in range(n):
		a += [list(map(int, list(stdin.readline())[:-1]))]
	for i in range(n):
		j = i // 3 + 3 * (i % 3)
		a[i][j] = 1 + (a[i][j] + 1) % 9
	for i in range(n):
		print(''.join(map(str, a[i])))


t = int(input())
for i in range(t):
	a = list()
	move = list()
	for j in range(9):
		s = list(input())
		a.append(s)
	i = 0
	for j in range(9):
		if a[j][i] == '9':
			a[j][i] = '1'
		else:
			a[j][i] = chr(ord(a[j][i]) + 1)
		if (j + 1) % 3 == 0:
			i = (j + 1) // 3
		else:
			i = i + 3
	for j in range(9):
		print(''.join(a[j]))


for _ in range(int(input())):
	s = []
	for i in range(9):
		s.append(input())
	sol = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(len(s)):
		x = int(s[i][sol[i]]) + 1
		x %= 9
		if x == 0:
			x = 9
		s[i] = s[i][0:sol[i]] + str(x) + s[i][sol[i] + 1:9]
	for i in s:
		print(i)


t = int(input())
for tt in range(t):
	l = []
	for i in range(9):
		s = input()
		s = s.replace('2', '1', 1)
		l.append(s)
	for i in l:
		print(i)


testcases = int(input())
for testcase in range(testcases):
	dp = []
	for i in range(9):
		temp = input()
		temp1 = []
		for j in temp:
			temp1.append(int(j))
		dp.append(temp1)
	getindex = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		v = getindex[i]
		dp[v][i] = dp[8][i]
	if dp[8][8] != dp[8][0]:
		dp[8][8] = dp[8][0]
	else:
		dp[8][8] = dp[8][1]
	for i in dp:
		strs = ''
		for j in i:
			strs += str(j)
		print(strs)


import sys
from collections import Counter
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10 ** 6)
MAX_INT = 2 ** 62 - 1
MOD = 10 ** 9 + 7
test_cases = int(input())
for _ in range(test_cases):
	grid = []
	for _ in range(9):
		grid.append([int(s) for s in input().strip()])
	to_change = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
	for (i, j) in to_change:
		grid[i][j] = grid[i - 1][j]
	for row in grid:
		print(''.join((str(r) for r in row)))


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		A = [list(input().strip()) for _ in range(9)]
		for j in range(9):
			for i in range(9):
				if j == 0 and i == 2:
					print(A[0][0], end='')
				elif j == 1 and i == 5:
					print(A[1][3], end='')
				elif j == 2 and i == 8:
					print(A[2][6], end='')
				elif j == 3 and i == 1:
					print(A[3][2], end='')
				elif j == 4 and i == 4:
					print(A[4][5], end='')
				elif j == 5 and i == 7:
					print(A[5][8], end='')
				elif j == 6 and i == 0:
					print(A[6][1], end='')
				elif j == 7 and i == 3:
					print(A[7][4], end='')
				elif j == 8 and i == 6:
					print(A[8][7], end='')
				else:
					print(A[j][i], end='')
			print('')
main()


t = int(input())
while t:
	mat = []
	for i in range(9):
		x = input()
		l = list(map(int, x))
		mat.append(l)
	for i in range(9):
		for j in range(9):
			if mat[i][j] == 2:
				print(1, end='')
			else:
				print(mat[i][j], end='')
		print(end='\n')
	t = t - 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	arr = []
	for i in range(1, 10):
		arr.append(input().strip())
	for i in range(0, 9):
		t = ''
		for k in arr[i]:
			if k == '8':
				t += '2'
			else:
				t += k
		print(t)


for _ in range(int(input())):
	arr = []
	for i in range(9):
		s = input()
		temp = []
		for j in range(9):
			if s[j] == '8':
				temp.append('9')
			else:
				temp.append(s[j])
		arr.append(temp)
	for i in range(len(arr)):
		print(*arr[i], sep='')


def solve(sudoku):
	(x, y) = (0, 0)
	sudoku[x][y] = 1 if sudoku[x][y] == 9 else sudoku[x][y] + 1
	(x, y) = (1, 4)
	sudoku[x][y] = 1 if sudoku[x][y] == 9 else sudoku[x][y] + 1
	(x, y) = (2, 8)
	sudoku[x][y] = 1 if sudoku[x][y] == 9 else sudoku[x][y] + 1
	(x, y) = (3, 1)
	sudoku[x][y] = 1 if sudoku[x][y] == 9 else sudoku[x][y] + 1
	(x, y) = (4, 5)
	sudoku[x][y] = 1 if sudoku[x][y] == 9 else sudoku[x][y] + 1
	(x, y) = (5, 6)
	sudoku[x][y] = 1 if sudoku[x][y] == 9 else sudoku[x][y] + 1
	(x, y) = (6, 2)
	sudoku[x][y] = 1 if sudoku[x][y] == 9 else sudoku[x][y] + 1
	(x, y) = (7, 3)
	sudoku[x][y] = 1 if sudoku[x][y] == 9 else sudoku[x][y] + 1
	(x, y) = (8, 7)
	sudoku[x][y] = 1 if sudoku[x][y] == 9 else sudoku[x][y] + 1
	for row in range(9):
		for col in range(9):
			print(sudoku[row][col], end='')
		print()
numTestCase = int(input())
for t in range(numTestCase):
	sudoku = []
	for i in range(9):
		row = input()
		rowList = []
		for j in range(9):
			rowList.append(int(row[j]))
		sudoku.append(rowList)
	solve(sudoku)


gg = 'abcdefghijklmnopqrstuvwxyz'
t = int(input())
while t:
	t -= 1
	l = []
	ans = []
	for x in range(0, 9):
		s = str(input())
		l.append(s)
	for x in l:
		a = []
		for letter in x:
			if letter == '1':
				a.append('2')
			else:
				a.append(letter)
		ans.append(a)
	for x in range(0, 9):
		for y in range(0, 9):
			print(ans[x][y], end='')
		print()
	print()


import math
t = int(input())

def ret(l):
	if l == '2':
		return '1'
	else:
		return l
for _ in range(t):
	sudoku = []
	for i in range(9):
		row = [ret(c) for c in input()]
		print(''.join(row))


from math import *
from collections import *
t = int(input())
for y in range(t):
	l = []
	for i in range(9):
		l.append(list(input()))
	if l[0][0] == '1':
		l[0][0] = '2'
	else:
		l[0][0] = '1'
	if l[1][3] == '1':
		l[1][3] = '2'
	else:
		l[1][3] = '1'
	if l[2][6] == '1':
		l[2][6] = '2'
	else:
		l[2][6] = '1'
	if l[3][1] == '1':
		l[3][1] = '2'
	else:
		l[3][1] = '1'
	if l[4][4] == '1':
		l[4][4] = '2'
	else:
		l[4][4] = '1'
	if l[5][7] == '1':
		l[5][7] = '2'
	else:
		l[5][7] = '1'
	if l[6][2] == '1':
		l[6][2] = '2'
	else:
		l[6][2] = '1'
	if l[7][5] == '1':
		l[7][5] = '2'
	else:
		l[7][5] = '1'
	if l[8][8] == '1':
		l[8][8] = '2'
	else:
		l[8][8] = '1'
	for i in range(9):
		print(''.join(l[i]))


t = int(input())
for i in range(t):
	s = ''
	for j in range(9):
		ts = input()
		s += ts
	for n in [0, 12, 24, 28, 40, 52, 56, 68, 80]:
		if s[n] == '1':
			s = s[:n] + '2' + s[n + 1:]
		else:
			s = s[:n] + '1' + s[n + 1:]
	for j in range(9):
		print(s[j * 9:j * 9 + 9])


t = int(input())
i = t * 9
a = 1
while a <= i:
	b = input()
	print(b.replace('1', '7'))
	a = a + 1


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	pos = [(0, 6), (1, 1), (2, 5), (3, 8), (4, 2), (5, 4), (6, 7), (7, 0), (8, 3)]
	for i in range(t):
		num = []
		for j in range(9):
			s = str(input())
			num.append(s)
		ans = []
		for k in range(9):
			y = pos[k][1]
			temp = list(num[k])
			if y != 0:
				temp[y] = temp[y - 1]
			else:
				temp[y] = temp[y + 1]
			ans.append(''.join(temp))
		for a in ans:
			print(a)
main()


t = int(input())
for _ in range(t):
	a = [[] for i in range(9)]
	for i in range(9):
		a[i] = [int(i) for i in input()]
		for j in range(9):
			if a[i][j] == 1:
				a[i][j] = 2
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


t = int(input())
for i in range(t):
	a = []
	for j in range(9):
		b = input()
		c = []
		for j in b:
			c.append(j)
		a.append(c)
	a[0][1] = a[0][0]
	a[1][4] = a[1][3]
	a[2][7] = a[2][6]
	a[3][2] = a[3][0]
	a[4][5] = a[4][3]
	a[5][8] = a[5][6]
	a[6][0] = a[6][1]
	a[7][3] = a[7][4]
	a[8][6] = a[8][7]
	for j in a:
		print(''.join(j))


t = int(input())
for i in range(t):
	matr = []
	for i in range(9):
		matr.append(list(map(int, ' '.join(input()).split())))
	matr[0][0] = matr[0][1]
	matr[1][3] = matr[1][4]
	matr[2][6] = matr[2][7]
	matr[3][1] = matr[3][2]
	matr[4][4] = matr[4][5]
	matr[5][7] = matr[5][8]
	matr[6][2] = matr[6][3]
	matr[7][5] = matr[7][6]
	matr[8][8] = matr[8][7]
	for i in range(9):
		print(''.join(map(str, matr[i])))


nt = int(input())
for c in range(nt):
	a = []
	for v in range(9):
		l = list(map(int, list(input())))
		a.append(l)
	j = i = 0
	while i < 9 and j < 9:
		if a[i][j] != 1:
			a[i][j] = 1
		else:
			a[i][j] = 2
		if j < 6:
			i += 1
			j += 3
		else:
			i += 1
			j -= 5
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


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

	def func(i):
		a = input()
		sim = str(10 - int(a[i])) if a[i] != '5' else '4'
		print(a[:i] + sim + a[i + 1:])
	func(0)
	func(3)
	func(6)
	func(1)
	func(4)
	func(7)
	func(2)
	func(5)
	func(8)


for _ in range(int(input())):
	for i in range(9):
		s = input()
		for i in s:
			if i == '3':
				print('7', end='')
			else:
				print(i, end='')
		print()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	ar = []
	for i in range(9):
		s = input()
		br = list(s)
		ar.append(br)
	for i in range(9):
		for j in range(9):
			if ar[i][j] == '1':
				ar[i][j] = '2'
			if ar[i][j] == '2':
				ar[i][j] = '1'
			print(ar[i][j], end='')
		print()


t = int(input())
for i in range(t):
	grid = []
	for i in range(9):
		row = input()
		row = list(row)
		for j in range(9):
			if row[j] == '2':
				row[j] = '1'
		grid.append(''.join(row))
	for k in range(9):
		print(grid[k])


import sys

class DAntiSudoku:

	def solve(self):
		for _ in range(int(input())):
			s = []
			n = 9
			for i in range(n):
				s.append([int(_) for _ in list(input().strip())])
			for (i, j) in zip(range(9), [0, 4, 8] + [1, 5, 6] + [2, 3, 7]):
				val = s[i][j]
				k = -1
				for k in range(1, 10):
					if k != val:
						break
				s[i][j] = k
			for line in s:
				print(*line, sep='')
solver = DAntiSudoku()
input = sys.stdin.readline
solver.solve()


def x(data, i):
	if len(set(data[i])) == 9:
		return True

def y(data, i):
	s = ''
	for d in data:
		s += d[i]
	if len(set(s)) == 9:
		return True

def s(data):
	for (xx, yy) in [(0, 0), (3, 0), (6, 0), (0, 3), (3, 3), (6, 3), (0, 6), (3, 6), (6, 6)]:
		s = ''
		res = []
		for i in range(xx, xx + 3):
			for j in range(yy, yy + 3):
				s += data[i][j]
				res.append((i, j))
		if len(set(s)) == 9:
			yield res

def main():
	d = int(input())
	for i in range(d):
		data = []
		for i in range(9):
			data.append([v for v in input()])
		dd = [0, 4, 8, 1, 5, 6, 2, 3, 7]
		for (i, v) in enumerate(dd):
			data[i][v] = str(int(data[i][v]) + 1) if data[i][v] != '9' else '1'
		for dd in data:
			print(''.join(dd))
main()


for t in range(int(input())):
	d = [list(input()) for i in range(9)]
	newd = []
	for i in d:
		k = i.index('1')
		i[k // 3 * 3 + (k + 1) % 3] = '1'
		newd.append(i)
	for i in newd:
		print(*i, sep='')


T = int(input())
for t in range(T):
	sudoku = [list(map(int, input())) for _ in range(9)]
	for i in range(9):
		for j in range(9):
			if sudoku[i][j] == 2:
				sudoku[i][j] = 1
	for row in sudoku:
		print(''.join(map(str, row)))


for _ in range(int(input())):
	s = []
	for i in range(9):
		a = list(input())
		a = list(map(int, a))
		s.append(a)
	indexes = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for elem in indexes:
		if s[elem[0]][elem[1]] == 9:
			s[elem[0]][elem[1]] = 1
		else:
			s[elem[0]][elem[1]] = s[elem[0]][elem[1]] + 1
	for st in s:
		st = list(map(str, st))
		print(''.join(st))


t = int(input())
for i in range(t):
	sud = [0] * 9
	for j in range(9):
		sud[j] = list(map(lambda x: ord(x) - ord('0'), input()))
	pairs = [(j, j % 3 * 3 + j // 3) for j in range(9)]
	for pair in pairs:
		sud[pair[0]][pair[1]] = sud[pair[0]][pair[1] - 1]
	for j in range(9):
		print(''.join(map(lambda x: str(x), sud[j])))


ans = []
for t in range(int(input())):
	lst = []
	for i in range(9):
		lst += [list(input())]
	dg = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	lst[0][0] = dg[int(lst[0][0]) - 2]
	lst[1][3] = dg[int(lst[1][3]) - 2]
	lst[2][6] = dg[int(lst[2][6]) - 2]
	lst[3][1] = dg[int(lst[3][1]) - 2]
	lst[4][4] = dg[int(lst[4][4]) - 2]
	lst[5][8] = dg[int(lst[5][8]) - 2]
	lst[6][2] = dg[int(lst[6][2]) - 2]
	lst[7][5] = dg[int(lst[7][5]) - 2]
	lst[8][7] = dg[int(lst[8][7]) - 2]
	for i in lst:
		ans += [i]
[print(*i, sep='') for i in ans]


t = int(input())
for q in range(t):
	l = []
	for i in range(9):
		u = input()
		p = ''
		for j in range(9):
			if u[j] == '2':
				p += '1'
			else:
				p += u[j]
		l.append(p)
	for i in l:
		print(i)


import sys
input = sys.stdin.readline
from collections import defaultdict as dd
t = int(input())
while t:
	su = []
	ll = []
	for i in range(9):
		l = list(map(int, input().strip()))
		ll.append(l)
		for j in range(9):
			if ll[i][j] == 1:
				ll[i][j] = 2
	for i in ll:
		print(*i, sep='')
	t -= 1


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	ar = []
	for i in range(9):
		ar.append(inp())
	print('')
	for i in range(9):
		s = list(ar[i])
		for j in range(9):
			if s[j] == '1':
				s[j] = '2'
				break
		print(''.join(s))


for _ in range(int(input())):
	s = []
	for i in range(9):
		s.append(list(input()))
	lis = [0, 3, 6]
	c = 0
	for i in range(9):
		if s[i][lis[c]] == '9':
			s[i][lis[c]] = '8'
		else:
			s[i][lis[c]] = str(int(s[i][lis[c]]) + 1)
		lis[c] += 1
		c = (c + 1) % 3
	for i in range(9):
		for j in range(9):
			print(s[i][j], end='')
		print()


def replace(board, i, j):
	board[i][j] = board[i][j] + 1 if board[i][j] < 9 else board[i][j] - 1

def solve(board):
	replace(board, 0, 0)
	replace(board, 3, 1)
	replace(board, 6, 2)
	replace(board, 1, 3)
	replace(board, 4, 4)
	replace(board, 7, 5)
	replace(board, 2, 6)
	replace(board, 5, 7)
	replace(board, 8, 8)
	return board

def display(board):
	result = ''
	for row in board:
		result += ''.join([str(x) for x in row]) + '\n'
	return result.strip()
for i in range(int(input())):
	board = [[int(x) for x in input()] for i in range(9)]
	print(display(solve(board)))


t = int(input())
for _ in range(t):
	matrix = [input() for _ in range(9)]
	for (i, j) in [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]:
		if matrix[i][j] == '1':
			matrix[i] = matrix[i][:j] + '2' + matrix[i][j + 1:]
		else:
			matrix[i] = matrix[i][:j] + '1' + matrix[i][j + 1:]
	for x in matrix:
		print(x)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	graph = []
	res = [[] for _ in range(9)]
	for i in range(9):
		temp = input()
		for j in range(9):
			res[i].append(temp[j])
	if res[0][0] == '9':
		res[0][0] = '8'
	else:
		res[0][0] = int(res[0][0]) + 1
	if res[1][4] == '9':
		res[1][4] = '8'
	else:
		res[1][4] = int(res[1][4]) + 1
	if res[2][6] == '9':
		res[2][6] = '8'
	else:
		res[2][6] = int(res[2][6]) + 1
	if res[3][1] == '9':
		res[3][1] = '8'
	else:
		res[3][1] = int(res[3][1]) + 1
	if res[4][3] == '9':
		res[4][3] = '8'
	else:
		res[4][3] = int(res[4][3]) + 1
	if res[5][7] == '9':
		res[5][7] = '8'
	else:
		res[5][7] = int(res[5][7]) + 1
	if res[6][2] == '9':
		res[6][2] = '8'
	else:
		res[6][2] = int(res[6][2]) + 1
	if res[7][5] == '9':
		res[7][5] = '8'
	else:
		res[7][5] = int(res[7][5]) + 1
	if res[8][8] == '9':
		res[8][8] = '8'
	else:
		res[2 + 6][6 + 2] = int(res[8][8]) + 1
	for i in range(9):
		for j in range(9):
			print(res[i][j], end='')
		print()


for u in range(int(input())):
	x = []
	for i in range(9):
		x.append(list(str(input())))
	for i in range(9):
		for j in range(9):
			if x[i][j] == '7':
				x[i][j] = '9'
	for i in range(9):
		print(''.join(x[i]))


t = int(input())
for _ in range(t):
	grid = []
	for _ in range(9):
		grid.append([int(i) for i in input()])
	columns = []
	to_change = []
	for i in range(9):
		row = grid[i]
		next_row = grid[(i + 1) % 9]
		prev_row = grid[(i - 1) % 9]
		prev_row_2 = grid[(i - 2) % 9]
		table = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
		if i % 3 == 0:
			options = table[next_row.index(1) // 3]
		elif i % 3 == 1:
			options = table[3 - (row.index(1) // 3 + prev_row.index(1) // 3)]
		else:
			options = table[3 - columns[-1] // 3 - columns[-2] // 3]
		for j in options:
			if j not in columns:
				columns.append(j)
				break
	for i in range(9):
		grid[i][columns[i]] = 1
	for row in grid:
		print(''.join([str(i) for i in row]))


for _ in range(int(input())):
	a = []
	s = input()
	x = int(s[0]) + 1
	if x == 10:
		x = 1
	i = 0
	y = s[:i] + str(x) + s[i + 1:]
	a.append(y)
	s = input()
	x = int(s[3]) + 1
	if x == 10:
		x = 1
	i = 3
	y = s[:i] + str(x) + s[i + 1:]
	a.append(y)
	s = input()
	x = int(s[6]) + 1
	if x == 10:
		x = 1
	i = 6
	y = s[:i] + str(x) + s[i + 1:]
	a.append(y)
	s = input()
	x = int(s[1]) + 1
	if x == 10:
		x = 1
	i = 1
	y = s[:i] + str(x) + s[i + 1:]
	a.append(y)
	s = input()
	x = int(s[4]) + 1
	if x == 10:
		x = 1
	i = 4
	y = s[:i] + str(x) + s[i + 1:]
	a.append(y)
	s = input()
	x = int(s[7]) + 1
	if x == 10:
		x = 1
	i = 7
	y = s[:i] + str(x) + s[i + 1:]
	a.append(y)
	s = input()
	x = int(s[2]) + 1
	if x == 10:
		x = 1
	i = 2
	y = s[:i] + str(x) + s[i + 1:]
	a.append(y)
	s = input()
	x = int(s[5]) + 1
	if x == 10:
		x = 1
	i = 5
	y = s[:i] + str(x) + s[i + 1:]
	a.append(y)
	s = input()
	x = int(s[8]) + 1
	if x == 10:
		x = 1
	i = 8
	y = s[:i] + str(x) + s[i + 1:]
	a.append(y)
	for j in a:
		print(j)


T = int(input())
for _ in range(T):
	li = []
	for i in range(9):
		temp = list(input())
		li.append(temp)
	li[0][1] = li[0][0]
	li[1][4] = li[1][3]
	li[2][7] = li[2][6]
	li[3][2] = li[3][1]
	li[4][5] = li[4][4]
	li[5][8] = li[5][7]
	li[6][0] = li[6][2]
	li[7][3] = li[7][5]
	li[8][6] = li[8][8]
	for i in range(9):
		s = ''
		for j in range(9):
			s = s + str(li[i][j])
		print(s)


from collections import Counter
for _ in range(int(input())):
	c = 0
	g = []
	for x in range(3):
		c = x
		for y in range(3):
			r = list(map(int, input()))
			r[c] = r[c] % 9 + 1
			c += 3
			g.append(r[:])
	for x in g:
		print(''.join(map(str, x)))


for t in range(int(input())):
	ar = []
	for k in range(9):
		ar.append(list(input()))
	ar[0][0] = ar[1][0]
	ar[3][1] = ar[4][1]
	ar[6][2] = ar[7][2]
	ar[1][3] = ar[2][3]
	ar[4][4] = ar[5][4]
	ar[7][5] = ar[8][5]
	ar[2][6] = ar[0][6]
	ar[5][7] = ar[3][7]
	ar[8][8] = ar[6][8]
	for k in ar:
		print(''.join(k))


t = int(input())
for i in range(t):
	arr = []
	for j in range(9):
		arr.append([0 for x in range(9)])
	for j in range(9):
		lul = list(map(int, list(input())))
		for x in range(9):
			arr[j][x] = lul[x] - 1
	print()
	arr[0][0] += 1
	arr[3][1] += 1
	arr[6][2] += 1
	arr[1][3] += 1
	arr[4][4] += 1
	arr[7][5] += 1
	arr[2][6] += 1
	arr[5][7] += 1
	arr[8][8] += 1
	for j in range(9):
		for k in range(9):
			val = arr[j][k] % 9
			print(val + 1, end='')
		print()


import sys
import math
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
from functools import reduce
sys.setrecursionlimit(10 ** 6)

def inputt():
	return sys.stdin.readline().strip()

def printt(n):
	sys.stdout.write(str(n) + '\n')

def listt():
	return [int(i) for i in inputt().split()]

def gcd(a, b):
	return math.gcd(a, b)

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

def factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(math.sqrt(n)) + 1, step) if n % i == 0)))

def comb(n, k):
	factn = math.factorial(n)
	factk = math.factorial(k)
	fact = math.factorial(n - k)
	ans = factn // (factk * fact)
	return ans

def is_prime(n):
	if n <= 1:
		return False
	if n == 2:
		return True
	if n > 2 and n % 2 == 0:
		return False
	max_div = math.floor(math.sqrt(n))
	for i in range(3, 1 + max_div, 2):
		if n % i == 0:
			return False
	return True

def maxpower(n, x):
	B_max = int(math.log(n, x)) + 1
	return B_max
t = int(inputt())
for _ in range(t):
	for i in range(9):
		s = inputt()
		s = s.replace('2', '1')
		printt(s)


for _ in range(int(input())):
	soduko = []
	for i in range(9):
		p = input()
		soduko.append([int(i) for i in p])
	soduko[0][0] = soduko[0][0] + 1 if soduko[0][0] != 9 else 8
	soduko[4][1] = soduko[4][1] + 1 if soduko[4][1] != 9 else 8
	soduko[8][2] = soduko[8][2] + 1 if soduko[8][2] != 9 else 8
	soduko[1][4] = soduko[1][4] + 1 if soduko[1][4] != 9 else 8
	soduko[5][5] = soduko[5][5] + 1 if soduko[5][5] != 9 else 8
	soduko[6][3] = soduko[6][3] + 1 if soduko[6][3] != 9 else 8
	soduko[2][8] = soduko[2][8] + 1 if soduko[2][8] != 9 else 8
	soduko[3][6] = soduko[3][6] + 1 if soduko[3][6] != 9 else 8
	soduko[7][7] = soduko[7][7] + 1 if soduko[7][7] != 9 else 8
	for i in range(9):
		for j in range(9):
			print(soduko[i][j], end='')
		print()


from functools import reduce
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(delimiter=' '):
		return input().split(delimiter)

	@staticmethod
	def list_int(delimiter=' '):
		return list(map(int, input().split(delimiter)))

def main():
	t = Read.int()
	for _ in range(t):
		a = []
		for i in range(9):
			a.append(list(Read.string()))
		a[0][0] = str(int(a[0][0]) + 1) if int(a[0][0]) != 9 else '1'
		a[1][4] = str(int(a[1][4]) + 1) if int(a[1][4]) != 9 else '1'
		a[2][8] = str(int(a[2][8]) + 1) if int(a[2][8]) != 9 else '1'
		a[3][1] = str(int(a[3][1]) + 1) if int(a[3][1]) != 9 else '1'
		a[4][5] = str(int(a[4][5]) + 1) if int(a[4][5]) != 9 else '1'
		a[5][6] = str(int(a[5][6]) + 1) if int(a[5][6]) != 9 else '1'
		a[6][2] = str(int(a[6][2]) + 1) if int(a[6][2]) != 9 else '1'
		a[7][3] = str(int(a[7][3]) + 1) if int(a[7][3]) != 9 else '1'
		a[8][7] = str(int(a[8][7]) + 1) if int(a[8][7]) != 9 else '1'
		for i in a:
			print(''.join(i))
main()


import sys

def read_line():
	return sys.stdin.readline()

def solve(lst):
	pos = [[0, 0], [1, 4], [2, 8], [3, 1], [4, 5], [5, 6], [6, 2], [7, 3], [8, 7]]
	for p in pos:
		lst[p[0]][p[1]] = str((int(lst[p[0]][p[1]]) + 1) % 9 + 1)
	for i in lst:
		print(''.join(i))
n = int(read_line())
for i in range(n):
	lst = []
	for i in range(9):
		lst.append([i for i in read_line()[:-1]])
	solve(lst)


for _ in range(int(input())):
	for i in range(9):
		a = input()
		a = list(a)
		for j in range(len(a)):
			if a[j] == '2':
				a[j] = '1'
				break
		for l in a:
			print(l, end='')
		print()


from sys import stdin
t = int(stdin.readline())
while t:
	t -= 1
	for i in range(9):
		a = input()
		for e in a:
			if e == '2':
				e = '1'
			print(e, end='')
		print()


for _ in range(int(input())):
	for _ in range(9):
		k = input()
		a = k.replace('4', '5')
		print(a)


for _ in range(int(input())):
	ls = [0] * 9
	for i in range(9):
		t = input()
		ls[i] = [int(x) for x in t]
	for i in range(9):
		for j in range(9):
			if ls[i][j] == 2:
				ls[i][j] = 1
	for i in range(9):
		for x in ls[i]:
			print(x, end='')
		print('')


for i in range(int(input())):
	ans = []
	for r in range(9):
		s = str(input())
		s = s.replace('1', '2')
		ans.append(s)
	for r in ans:
		print(r)


for _ in range(int(input())):
	board = []
	for i in range(9):
		board.append(list(str(input())))
	for r in range(9):
		for c in range(9):
			if board[r][c] == '2':
				board[r][c] = '1'
	for i in range(9):
		s = ''.join(board[i])
		print(int(s))


from collections import Counter
gi = lambda : list(map(int, input().split()))
for _ in range(gi()[0]):
	g = [list(input()) for e in range(9)]
	g[0][0] = '1' if g[0][0] != '1' else '2'
	g[3][1] = '1' if g[3][1] != '1' else '2'
	g[6][2] = '1' if g[6][2] != '1' else '2'
	g[1][3] = '1' if g[1][3] != '1' else '2'
	g[4][4] = '1' if g[4][4] != '1' else '2'
	g[7][5] = '1' if g[7][5] != '1' else '2'
	g[2][6] = '1' if g[2][6] != '1' else '2'
	g[5][7] = '1' if g[5][7] != '1' else '2'
	g[8][8] = '1' if g[8][8] != '1' else '2'
	print('\n'.join([''.join(e) for e in g]))


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def main():
	try:
		for _ in range(inp()):
			arr = []
			for i in range(9):
				arr.append(list(input()))
			for i in range(9):
				for j in range(9):
					if arr[i][j] == '1':
						arr[i][j] = '2'
			for i in arr:
				print(''.join(i))
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin
t = int(stdin.readline().rstrip())
for _ in range(t):
	for i in range(9):
		n = list(stdin.readline().rstrip())
		if i == 0:
			n[6] = n[5]
		elif i == 1:
			n[1] = n[0]
		elif i == 2:
			n[5] = n[8]
		elif i == 3:
			n[8] = n[5]
		elif i == 4:
			n[2] = n[0]
		elif i == 5:
			n[4] = n[7]
		elif i == 6:
			n[7] = n[6]
		elif i == 7:
			n[0] = n[1]
		elif i == 8:
			n[3] = n[2]
		print(''.join(n))


t = int(input())
sud = [[list(map(str, input())) for i in range(9)] for j in range(t)]
for i in sud:
	for j in range(0, 3):
		i[j][j * 3] = i[j][j * 3 + 1]
	for j in range(3, 6):
		i[j][(j - 3) * 3 + 2] = i[j][(j - 3) * 3 + 1]
	for j in range(6, 9):
		i[j][(j - 6) * 3 + 1] = i[j][(j - 6) * 3 + 2]
	for j in i:
		print(*j, sep='')


s1 = []
for i in range(1, 10):
	s1.append(str(i))
t = int(input())
for i in range(t):
	s = []
	for j in range(9):
		y = input().rstrip()
		y = [i for i in y]
		s.append(y)
	for i in s1:
		if s[0][0] != i:
			s[0][0] = i
			break
	for i in s1:
		if s[1][3] != i:
			s[1][3] = i
			break
	for i in s1:
		if s[2][6] != i:
			s[2][6] = i
			break
	for i in s1:
		if s[3][1] != i:
			s[3][1] = i
			break
	for i in s1:
		if s[4][4] != i:
			s[4][4] = i
			break
	for i in s1:
		if s[5][7] != i:
			s[5][7] = i
			break
	for i in s1:
		if s[6][2] != i:
			s[6][2] = i
			break
	for i in s1:
		if s[7][5] != i:
			s[7][5] = i
			break
	for i in s1:
		if s[8][8] != i:
			s[8][8] = i
			break
	for i in s:
		print(''.join(i))


def r(t=int):
	return list(map(t, input().split()))

def ri(t=int):
	return list(map(t, input().split()))[0]

def cd(it):
	ret_val = dict()
	for v in it:
		ret_val[v] = ret_val.get(v, 0) + 1
	return ret_val
for _ in range(ri()):
	a = []
	for i in range(9):
		a.append(list(input()))
	for i in range(3):
		values = set()
		for j in range(3):
			values.add(a[j + i * 3][j * 3 + i])
		for g in '123456789':
			if g not in values:
				break
		for j in range(3):
			a[j + i * 3][j * 3 + i] = g
	for line in a:
		print(''.join(line))


coords = [(2, 2), (1, 4), (0, 6), (4, 1), (5, 3), (3, 8), (6, 0), (7, 5), (8, 7)]
for _ in range(int(input())):
	l = [list(input()) for i in range(9)]
	for i in coords:
		l[i[0]][i[1]] = l[i[0] - 1][i[1]]
	print(*(''.join(i) for i in l), sep='\n')


t = int(input())
for _ in range(t):
	arr = []
	for i in range(9):
		temp = list(input())
		arr.append(temp)
	p = 8
	t = 0
	for i in range(9):
		arr[i][p] = arr[i][p - 1]
		print(''.join(arr[i]))
		p = (p + 2) % 9


def yo():
	t = int(input())
	l = []
	for i in range(t):
		l.extend([input().replace('1', '2') for j in range(9)])
	print('\n'.join(l))
yo()


n = int(input()) * 9
for _ in range(n):
	n = input()
	m = n.index('2')
	print(n[:m], '5', n[m + 1:], sep='')


import string
import random
t = int(input())
for i in range(t):
	matrix = []
	for j in range(9):
		matrix.append([int(k) for k in list(input())])
	for k in range(9):
		for j in range(9):
			if matrix[k][j] == 1:
				matrix[k][j] = 2
	for k in range(9):
		print(*matrix[k], sep='', end='\n')


for _ in range(int(input())):
	a = []
	for i in range(9):
		a.append(input())
	k = 0
	for i in range(9):
		b = list(a[i])
		if b[k] == '1':
			b[k] = '2'
		else:
			b[k] = '1'
		k += 3
		k %= 8
		if k == 0:
			k = 8
		print(''.join((e for e in b)))


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	sq = []
	target = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for i in range(9):
		ln = sys.stdin.readline().rstrip()
		tmp = []
		for c in ln:
			tmp.append(int(c))
		sq.append(tmp)
	for i in target:
		if sq[i[0]][i[1]] < 9:
			sq[i[0]][i[1]] = sq[i[0]][i[1]] + 1
		else:
			sq[i[0]][i[1]] = sq[i[0]][i[1]] - 1
	for i in range(9):
		for j in range(9):
			print(sq[i][j], end='')
		print('')


from sys import stdin, stdout
for test in range(int(stdin.readline())):
	temp = [0, 3, 6, 1, 4, 7]
	sudo = []
	for i in range(6):
		arr = stdin.readline()
		arr = arr[:temp[i]] + arr[temp[i] + 1] + arr[temp[i] + 1:]
		sudo.append(arr)
	temp = [2, 5, 8]
	for i in range(3):
		arr = stdin.readline()
		arr = arr[:temp[i]] + arr[temp[i] - 2] + arr[temp[i] + 1:]
		sudo.append(arr)
	for i in range(9):
		stdout.write(sudo[i])


for _ in range(0, int(input())):
	sudoku = [0, 0, 0, 0, 0, 0, 0, 0, 0]
	modify = {0: 0, 1: 3, 2: 6, 3: 1, 4: 4, 5: 7, 6: 2, 7: 5, 8: 8}
	pool = {1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 1}
	for row in range(0, 9):
		temp = input()
		for line in range(0, 9):
			if line == modify[row]:
				sudoku[line] = pool[int(temp[line])]
			else:
				sudoku[line] = int(temp[line])
			print(sudoku[line], end='')
		print()


t = int(input())
arr = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for i in range(t):
	for i in range(9):
		s = list(input())
		if s[arr[i]] == '1':
			s[arr[i]] = '2'
		else:
			s[arr[i]] = '1'
		print(''.join(s))


t = int(input())
for test in range(0, t):
	sudoku = []
	line = list(map(int, list(input())))
	line[0] = line[0] + 1
	if line[0] == 10:
		line[0] = 1
	sudoku.append(line)
	line = list(map(int, list(input())))
	line[3] = line[3] + 1
	if line[3] == 10:
		line[3] = 1
	sudoku.append(line)
	line = list(map(int, list(input())))
	line[6] = line[6] + 1
	if line[6] == 10:
		line[6] = 1
	sudoku.append(line)
	line = list(map(int, list(input())))
	line[1] = line[1] + 1
	if line[1] == 10:
		line[1] = 1
	sudoku.append(line)
	line = list(map(int, list(input())))
	line[4] = line[4] + 1
	if line[4] == 10:
		line[4] = 1
	sudoku.append(line)
	line = list(map(int, list(input())))
	line[7] = line[7] + 1
	if line[7] == 10:
		line[7] = 1
	sudoku.append(line)
	line = list(map(int, list(input())))
	line[2] = line[2] + 1
	if line[2] == 10:
		line[2] = 1
	sudoku.append(line)
	line = list(map(int, list(input())))
	line[5] = line[5] + 1
	if line[5] == 10:
		line[5] = 1
	sudoku.append(line)
	line = list(map(int, list(input())))
	line[8] = line[8] + 1
	if line[8] == 10:
		line[8] = 1
	sudoku.append(line)
	for line in sudoku:
		s_line = list(map(str, line))
		print(''.join(s_line))


def hhh(i, j):
	x[i][j] += 1
	if x[i][j] == 10:
		x[i][j] = 1
for t in range(int(input())):
	x = []
	for a in range(9):
		a = list(map(int, list(input())))
		x.append(a)
	hhh(0, 0)
	hhh(1, 3)
	hhh(2, 6)
	hhh(3, 1)
	hhh(4, 4)
	hhh(5, 7)
	hhh(6, 2)
	hhh(7, 5)
	hhh(8, 8)
	for i in range(9):
		print(''.join(map(str, x[i])))


def change(sudocu, i, j):
	sudocu[i][j] = 1 if sudocu[i][j] == 9 else sudocu[i][j] + 1
t = int(input())
for req in range(t):
	sudocu = [list(map(int, list(input()))) for _ in range(9)]
	change(sudocu, 0, 0)
	change(sudocu, 3, 1)
	change(sudocu, 6, 2)
	change(sudocu, 1, 3)
	change(sudocu, 4, 4)
	change(sudocu, 7, 5)
	change(sudocu, 2, 6)
	change(sudocu, 5, 7)
	change(sudocu, 8, 8)
	for line in sudocu:
		print(''.join(list(map(str, line))))


for i in range(int(input())):
	a = []
	for j in range(9):
		a.append(list(input()))
	for j in range(3):
		for k in range(3):
			if j == 2:
				a[j * 3 + k][3 * k + j] = a[j * 3 + k][3 * k + j - 1]
			else:
				a[j * 3 + k][3 * k + j] = a[j * 3 + k][3 * k + j + 1]
	for j in range(9):
		for k in range(9):
			print(a[j][k], end='')
		print()


t = int(input())
for i in range(t):
	sv = []
	for j in range(9):
		s = input()
		vec = []
		for i in s:
			vec.append(int(i))
		sv.append(vec)
	sv[0][0] = sv[0][1]
	sv[1][4] = sv[1][5]
	sv[2][8] = sv[2][7]
	sv[3][1] = sv[3][2]
	sv[4][3] = sv[4][2]
	sv[5][6] = sv[5][7]
	sv[6][2] = sv[6][1]
	sv[7][5] = sv[7][4]
	sv[8][7] = sv[8][8]
	for j in sv:
		l = [str(f) for f in j]
		print(''.join(l))


for _ in range(int(input())):
	s = [[*map(int, input())] for _ in range(9)]
	for i in range(3):
		for j in range(3):
			s[i * 3 + j][j * 3 + i] = s[i * 3 + j][j * 3 + i] % 9 + 1
	print('\n'.join((''.join(map(str, t)) for t in s)))


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd, log
from random import choice
for _ in range(int(input())):
	l = []
	for _ in range(9):
		l.append(list(input()))
	l[0][0] = l[0][1]
	l[1][3] = l[1][4]
	l[2][6] = l[2][7]
	l[3][1] = l[3][2]
	l[4][4] = l[4][5]
	l[5][7] = l[5][8]
	l[6][2] = l[6][3]
	l[7][5] = l[7][6]
	l[8][8] = l[7][8]
	for i in l:
		print(''.join(i))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	mat = [list(sys.stdin.readline()) for _ in range(9)]
	for i in range(9):
		for j in range(9):
			if mat[i][j] == '1':
				mat[i][j] = '2'
	for i in range(9):
		print(''.join(mat[i]), end='')


for _ in range(int(input())):
	grid = [input() for _ in range(9)]
	for row in grid:
		for num in row:
			if num == '2':
				print('1', end='')
			else:
				print(num, end='')
		print()


t = int(input())
for i in range(0, t):
	strList = []
	for k in range(0, 9):
		str = input()
		newStr = str.replace('1', '2')
		print(newStr)


for _ in range(int(input())):
	L = []
	for i in range(9):
		L.append(list(input()))
	for i in range(9):
		for j in range(9):
			if L[i][j] == '1':
				L[i][j] = '9'
	for i in range(9):
		S = ''.join(L[i])
		print(S)


def display(arr, n):
	for i in arr:
		for j in i:
			print(j, end='')
		print()
n = 9
t = int(input())
for _ in range(t):
	arr = [[] for _ in range(n)]
	for (i, _) in enumerate(arr):
		s = input()
		arr[i] = [1 if x == '9' else int(x) for x in s]
	display(arr, n)


import sys

def data():
	return sys.stdin.readline().strip()
out = sys.stdout.write

def mdata():
	return map(int, data().split())
from collections import defaultdict as dd
for t in range(int(data())):
	l = []
	for i in range(9):
		a = str(data())
		l.append(list(a))
	k = 0
	i = 0
	while i < 9:
		for j in range(3):
			l[i][k + j * 3] = l[i][(k + j * 3 + 1) % 9]
			i += 1
		k += 1
	for i in range(9):
		out(''.join(l[i]) + '\n')


t = int(input())
for sample in range(t):
	sudoku = [list(input()) for row in range(9)]
	col = None
	for i in range(9):
		if i % 3 == 0:
			col = iter(range(i // 3, 9, 3))
		j = next(col)
		if sudoku[i][j] == '1':
			sudoku[i][j] = '2'
		else:
			sudoku[i][j] = '1'
	for row in sudoku:
		print(''.join(row), sep='\n')


from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect

def solve(inf):
	mat = []
	for _ in range(9):
		a = list(map(int, input()))
		mat.append(a)
	i = 0
	for j in range(9):
		curr = mat[j][i % 9]
		next = curr - 1
		if next == 0:
			next = 9
		mat[j][i % 9] = next
		i += 4
	for row in mat:
		print(''.join([str(x) for x in row]))
for _ in range(int(input())):
	inf = []
	solve(inf)


t = int(input())
for j in range(t):
	answer = ''
	temp = input()
	a = int(temp[0]) + 1
	if a == 10:
		a -= 2
	answer = str(a)
	for i in range(1, 9):
		answer += temp[i]
	print(answer)
	temp = input()
	a = int(temp[3]) + 1
	if a == 10:
		a -= 2
	answer = temp[0:3]
	answer += str(a)
	for i in range(4, 9):
		answer += temp[i]
	print(answer)
	temp = input()
	a = int(temp[6]) + 1
	if a == 10:
		a -= 2
	answer = str(temp[0:6])
	answer += str(a)
	for i in range(7, 9):
		answer += temp[i]
	print(answer)
	temp = input()
	a = int(temp[1]) + 1
	if a == 10:
		a -= 2
	answer = temp[0:1]
	answer += str(a)
	answer += temp[2:9]
	print(answer)
	temp = input()
	a = int(temp[4]) + 1
	if a == 10:
		a -= 2
	answer = temp[0:4]
	answer += str(a)
	answer += temp[5:9]
	print(answer)
	temp = input()
	a = int(temp[7]) + 1
	if a == 10:
		a -= 2
	answer = temp[0:7]
	answer += str(a)
	answer += temp[8:9]
	print(answer)
	temp = input()
	a = int(temp[2]) + 1
	if a == 10:
		a -= 2
	answer = temp[0:2]
	answer += str(a)
	answer += temp[3:9]
	print(answer)
	temp = input()
	a = int(temp[5]) + 1
	if a == 10:
		a -= 2
	answer = temp[0:5]
	answer += str(a)
	answer += temp[6:9]
	print(answer)
	temp = input()
	a = int(temp[8]) + 1
	if a == 10:
		a -= 2
	answer = temp[0:8]
	answer += str(a)
	answer += temp[9:9]
	print(answer)


def center(n):
	x = 1 + n // 3 * 3
	y = 1 + n % 3 * 3
	return (x, y)
N = int(input())
for _ in range(N):
	field = [[int(i) for i in input()] for j in range(9)]
	for i in range(9):
		if i == 0:
			field[0][0] = field[0][1]
		elif i == 1:
			field[1][3] = field[1][4]
		elif i == 2:
			field[2][6] = field[2][7]
		elif i == 3:
			field[3][1] = field[3][2]
		elif i == 4:
			field[4][4] = field[4][5]
		elif i == 5:
			field[5][7] = field[5][8]
		elif i == 6:
			field[6][2] = field[6][0]
		elif i == 7:
			field[7][5] = field[7][3]
		elif i == 8:
			field[8][8] = field[8][6]
	for i in field:
		print(''.join(list(map(str, i))))


for tango_charlie in range(int(input())):
	aa = []
	for i in range(9):
		l = list(input())
		aa.append(l)
	aa[0][0] = aa[1][0]
	aa[1][3] = aa[2][3]
	aa[2][6] = aa[3][6]
	aa[3][1] = aa[4][1]
	aa[4][4] = aa[5][4]
	aa[5][7] = aa[6][7]
	aa[6][2] = aa[7][2]
	aa[7][5] = aa[8][5]
	aa[8][8] = aa[8][7]
	for iii in range(9):
		print(''.join(aa[iii]))


from sys import stdin, stdout
from math import sqrt, ceil, gcd, log, log10

def rl(f=int):
	return [f(x) for x in stdin.readline().split()]
t = int(input())
for _ in range(t):
	board = []
	for _ in range(9):
		board.append(list(stdin.readline().strip()))
	for i in range(len(board)):
		for j in range(len(board[0])):
			if board[i][j] == '1':
				board[i][j] = '2'
	for row in board:
		print(''.join(row))


t = int(input())
for i in range(t):
	board = []
	for _ in range(9):
		board.append([int(x) for x in input()])
	for row in board:
		row = [x if x != 2 else 1 for x in row]
		print(''.join((str(x) for x in row)))


t = int(input())
for i in range(t):
	num1 = []
	for i in range(9):
		num2 = str(input())
		num3 = []
		for j in num2:
			num3.append(int(j))
		num1.append(num3)
	if num1[0][0] == 9:
		num1[0][0] = 1
	if num1[0][0] != 9:
		num1[0][0] += 1
	if num1[1][3] == 9:
		num1[1][3] = 1
	if num1[1][3] != 9:
		num1[1][3] += 1
	if num1[2][6] == 9:
		num1[2][6] = 1
	if num1[2][6] != 9:
		num1[2][6] += 1
	if num1[3][1] == 9:
		num1[3][1] = 1
	if num1[3][1] != 9:
		num1[3][1] += 1
	if num1[4][4] == 9:
		num1[4][4] = 1
	if num1[4][4] != 9:
		num1[4][4] += 1
	if num1[5][7] == 9:
		num1[5][7] = 1
	if num1[5][7] != 9:
		num1[5][7] += 1
	if num1[6][2] == 9:
		num1[6][2] = 1
	if num1[6][2] != 9:
		num1[6][2] += 1
	if num1[7][5] == 9:
		num1[7][5] = 1
	if num1[7][5] != 9:
		num1[7][5] += 1
	if num1[8][8] == 9:
		num1[8][8] = 1
	if num1[8][8] != 9:
		num1[8][8] += 1
	for i in num1:
		a = ''
		for j in i:
			a += str(j)
		print(a)


i = int(input())
for x in range(9 * i):
	a = input()
	b = a.split('2')
	print(b[0] + '1' + b[1])


t = int(input())
for _ in range(t):
	a = []
	for i in range(9):
		b = []
		x = input()
		for j in x:
			b.append(int(j))
		a.append(b)
	j = 0
	for i in range(9):
		if a[i][j] == 1:
			a[i][j] = 2
		else:
			a[i][j] = 1
		if i % 3 != 2:
			j = (j + 3) % 9
		else:
			j = (j + 4) % 9
	for i in range(9):
		for j in range(9):
			print(a[i][j], sep='', end='')
		print('')


t = int(input())
for _ in range(t):
	l = []
	for i in range(0, 9):
		a = input()
		a = list(a)
		for i in range(0, 9):
			a[i] = int(a[i])
			if a[i] == 1:
				a[i] = 2
				break
		l.append(a)
	for i in range(0, 9):
		for j in range(0, 9):
			print(l[i][j], end='')
		print()


for _ in range(int(input())):
	a = [list(map(int, list(input()))) for _ in range(9)]
	c = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for (x, y) in c:
		a[x][y] = a[x][y] + 1 if a[x][y] < 9 else 1
	print('\n'.join([''.join(map(str, row)) for row in a]))


t = int(input())
import random
while t:
	s = []
	for i in range(9):
		s.append(input())
	new_li = []
	for i in range(9):
		new_li.append(s[i].replace('5', '4'))
	for i in range(9):
		print(new_li[i])
	t -= 1


from sys import stdin, stdout
q = int(input())
for i in range(q):
	sudo = [[] for i in range(9)]
	for i in range(9):
		l = list(map(int, input()))
		for k in l:
			sudo[i].append(k)
	i = 0
	j = 0
	while i < 9:
		if i == 0:
			j = 0
		elif i == 1:
			j = 3
		elif i == 2:
			j = 6
		elif i == 3:
			j = 1
		elif i == 4:
			j = 4
		elif i == 5:
			j = 7
		elif i == 6:
			j = 2
		elif i == 7:
			j = 5
		elif i == 8:
			j = 8
		if sudo[i][j] != 1:
			sudo[i][j] = 1
		else:
			sudo[i][j] = 2
		i = i + 1
	for i in range(9):
		for j in range(9):
			print(sudo[i][j], end='')
		print()


def antisudoku(s):
	a = []
	j = 0
	for i in range(0, 9, 3):
		if 1 <= int(s[i][j]) <= 8:
			b = int(s[i][j]) + 1
		else:
			b = 1
		if 1 <= int(s[i + 1][j + 3]) <= 8:
			c = int(s[i + 1][j + 3]) + 1
		else:
			c = 1
		if 1 <= int(s[i + 2][j + 6]) <= 8:
			d = int(s[i + 2][j + 6]) + 1
		else:
			d = 1
		a.append(s[i][:j] + str(b) + s[i][j + 1:])
		a.append(s[i + 1][:j + 3] + str(c) + s[i + 1][j + 1 + 3:])
		a.append(s[i + 2][:j + 6] + str(d) + s[i + 2][j + 1 + 6:])
		j += 1
	for x in a:
		print(x)
	return
t = int(input())
s = []
for i in range(t):
	a = []
	for j in range(9):
		a.append(input())
	s.append(a)
for x in s:
	antisudoku(x)


for _ in range(int(input())):
	sudoku = []
	for _ in range(9):
		lo = str(input())
		sudoku.append([int(i) for i in lo])
	for i in range(9):
		for j in range(9):
			if sudoku[i][j] == 2:
				sudoku[i][j] = 1
	for i in range(9):
		for j in sudoku[i]:
			print(j, end='')
		print()


t = int(input())
for k in range(0, t):
	a = []
	for i in range(0, 9):
		p = input()
		p = list(p)
		a.append(p)
	a[0][0] = a[0][1]
	a[1][3] = a[1][2]
	a[2][6] = a[2][5]
	a[3][1] = a[3][2]
	a[4][4] = a[4][3]
	a[5][8] = a[5][7]
	a[6][2] = a[6][1]
	a[7][5] = a[7][4]
	a[8][7] = a[8][6]
	for i in range(0, 9):
		p = ''
		for j in range(0, 9):
			p = p + a[i][j]
		print(p)


def main():
	for t in range(int(input())):
		n1 = 9
		l = [[] for i in range(9)]
		for i in range(n1):
			l[i] = [int(j) for j in list(input())]
		ls = [(1, 1), (4, 2), (7, 3), (2, 4), (5, 5), (8, 6), (3, 7), (6, 8), (9, 9)]
		for n in ls:
			if l[n[0] - 1][n[1] - 1] == 5:
				l[n[0] - 1][n[1] - 1] = 9
			else:
				l[n[0] - 1][n[1] - 1] = 9 - l[n[0] - 1][n[1] - 1] + 1
		for i in range(n1):
			print(''.join(map(str, l[i])))
main()


for _ in range(int(input())):
	l = []
	f = 0
	ans = ''
	for i in range(9):
		ans = ''
		t = input()
		for j in range(9):
			if j == f:
				if t[j] != '9':
					ans += '9'
				else:
					ans += '8'
			else:
				ans += t[j]
		f += 3
		if f == 9:
			f = 1
		elif f == 10:
			f = 2
		print(ans)


t = int(input())
for z in range(t):
	a = []
	for i in range(9):
		s = list(input())
		for j in range(9):
			if s[j] == '2':
				s[j] = '3'
		a.append(''.join(s))
	for i in range(9):
		print(a[i])


def list__str(liste):
	a = ''
	for i in liste:
		a = a + str(i)
	return a
for i in range(int(input())):
	matr = []
	for i in range(9):
		array = []
		for i in input():
			array.append(i)
		matr.append(array)
	for i in matr:
		for j in range(9):
			if i[j] == '1':
				i[j] = '2'
	for i in matr:
		print(list__str(i))


t = int(input())
for test in range(t):
	a = []
	for i in range(9):
		a.append([])
		x = input()
		for j in x:
			a[i].append(int(j))
	l = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for e in l:
		i = e[0]
		j = e[1]
		a[i][j] = a[i][j] + 1
		if a[i][j] == 10:
			a[i][j] = 1
	for i in range(9):
		for j in range(9):
			print(a[i][j], end='')
		print()


for i in range(int(input())):
	l = []
	for j in range(9):
		p = [k for k in input()]
		l.append(p)
	m = [0, 0, 3, 1, 6, 2, 1, 3, 4, 4, 7, 5, 2, 6, 5, 7, 8, 8]
	for j in range(0, 18, 2):
		if l[m[j]][m[j + 1]] == '9':
			l[m[j]][m[j + 1]] = '1'
		else:
			l[m[j]][m[j + 1]] = str(int(l[m[j]][m[j + 1]]) + 1)
	for j in l:
		print(''.join(j))


t = int(input())
for _ in range(t):
	sudoku = []
	for i in range(9):
		sudoku.append(input())
	for l in sudoku:
		for c in l:
			if c == '1':
				print('9', end='')
			else:
				print(c, end='')
		print()


from sys import stdin, stdout
from math import *

def func(d, x, y):
	(r, c) = (0, 0)
	for i in range(9):
		if d[i][y] == '1':
			r += 1
	for i in range(9):
		if d[x][i] == '1':
			c += 1
	xx = 0
	yy = 0
	if x < 3:
		xx = 0
	elif x < 6:
		xx = 3
	elif x < 9:
		xx = 6
	if y < 3:
		yy = 0
	elif y < 6:
		yy = 3
	elif y < 9:
		yy = 6
	s = 0
	for i in range(xx, xx + 3):
		for j in range(yy, yy + 3):
			if d[i][j] == '1':
				s += 1
	return (r, c, s)
for __ in range(int(input())):
	d = []
	for i in range(9):
		d.append(list(input()))
	for i in range(9):
		for j in range(9):
			if d[i][j] == '1':
				d[i][j] = '2'
	for i in range(9):
		print(''.join(d[i]))


t = int(input())
for _ in range(t):
	mat = []
	arr_y = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for (x, y) in zip(range(9), arr_y):
		vec = list(input())
		for z in vec:
			if vec[y] != z:
				vec[y] = z
				break
		mat.append(''.join(vec))
	print('\n'.join(mat))


t = int(input())
for _ in range(t):
	sudoku = []
	for j in range(9):
		line = input()
		sudoku.append([int(x) for x in line])
	loop = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
	for (x, y) in loop:
		sudoku[x][y] += 1
		if sudoku[x][y] > 9:
			sudoku[x][y] = 1
	print('\n'.join((''.join((str(x) for x in y)) for y in sudoku)))


def column(matrix, i):
	return [row[i] for row in matrix]

def print_block(sudoku, pos):
	(row, col) = pos
	for i in range(3):
		for j in range(3):
			print(sudoku[row * 3 + i][col * 3 + j], end='')
		print('\n')

def fill(sudoku, pos):
	(row, col) = pos
	i = 1
	while not (row_test(sudoku[row]) and row_test(column(sudoku, col)) and block_test(sudoku, (row // 3, col // 3))):
		sudoku[row][col] = i
		i = i + 1

def solve(sudoku, n):
	for i in range(3):
		for j in range(3):
			padding = j
			fill(sudoku, (3 * i + j, 3 * j + (j + i) % 3))
	test(sudoku)

def row_test(a):
	b = set(a)
	if len(b) <= 8:
		return True

def block_test(sudoku, pos):
	(row, col) = pos
	a = []
	for i in range(3):
		for j in range(3):
			a.append(sudoku[row * 3 + i][col * 3 + j])
	a = set(a)
	if len(a) <= 8:
		return True

def print_ans(sudoku):
	for i in range(9):
		for j in range(9):
			print(sudoku[i][j], end='')
		print('')

def test(sudoku):
	flag = True
	for i in range(9):
		a = sudoku[i].copy()
		a.sort()
		flag = flag and row_test(a)
	for i in range(9):
		a = column(sudoku, i).copy()
		flag = flag and row_test(a)
	for i in range(3):
		for j in range(3):
			flag = flag and block_test(sudoku, (i, j))
	if flag:
		print_ans(sudoku)

def main():
	n = int(input())
	for i in range(n):
		sudoku = []
		for j in range(9):
			row = input()
			a = []
			for r in row:
				a.append(int(r))
			sudoku.append(a)
		solve(sudoku, n)
main()


from collections import defaultdict
from collections import Counter
from string import ascii_lowercase
import math
from sys import setrecursionlimit as srl
srl(2 * 10 ** 6)

def solve(r):
	for i in range(len(r)):
		for j in range(len(r[0])):
			if r[i][j] == '2':
				r[i][j] = '1'
	return r
t = int(input())
while t:
	k = 9
	r = []
	while k:
		r.append(list(input()))
		k -= 1
	for x in solve(r):
		print(''.join(x))
	t -= 1


for q in range(int(input())):
	a = []
	for i in range(9):
		a.append(list(input()))
	if a[0][0] == '1':
		a[0][0] = '9'
	else:
		a[0][0] = '1'
	if a[1][3] == '1':
		a[1][3] = '9'
	else:
		a[1][3] = '1'
	if a[2][6] == '1':
		a[2][6] = '9'
	else:
		a[2][6] = '1'
	if a[3][1] == '1':
		a[3][1] = '9'
	else:
		a[3][1] = '1'
	if a[4][4] == '1':
		a[4][4] = '9'
	else:
		a[4][4] = '1'
	if a[5][7] == '1':
		a[5][7] = '9'
	else:
		a[5][7] = '1'
	if a[6][2] == '1':
		a[6][2] = '9'
	else:
		a[6][2] = '1'
	if a[7][5] == '1':
		a[7][5] = '9'
	else:
		a[7][5] = '1'
	if a[8][8] == '1':
		a[8][8] = '9'
	else:
		a[8][8] = '1'
	for i in range(9):
		print(''.join(a[i]))


t = int(input())

def trans(x):
	return '1' if x == '9' else chr(ord(x) + 1)
for cas in range(t):
	s = []
	for i in range(9):
		ss = input()
		s.append(list(ss))
	for i in range(3):
		for j in range(3):
			s[i * 3 + j][j * 3 + i] = trans(s[i * 3 + j][j * 3 + i])
	for i in range(9):
		print(''.join(s[i]))


import sys

def func():
	return
for _ in range(int(input())):
	arr = []
	k = 0
	x = '615824703'
	for i in range(9):
		s = input().strip()
		ans = []
		for j in range(9):
			if j == int(x[k]):
				if int(s[int(x[k])]) < 9:
					ans.append(str(int(s[int(x[k])]) + 1))
				else:
					ans.append('1')
			else:
				ans.append(s[j])
		k += 1
		arr.append(''.join(ans))
	for i in range(9):
		print(arr[i])


import io
import os
from collections import Counter, defaultdict, deque

def solve(grid):
	for r in range(0, 9):
		c = r * 3 % 9 + r // 3
		if grid[r][c] != '1':
			grid[r][c] = '1'
		else:
			grid[r][c] = '9'
	return '\n'.join((''.join(row) for row in grid))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	grid = [list(input().decode().rstrip()) for i in range(9)]
	ans = solve(grid)
	print(ans)


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

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

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

def modInverse(p, a, m):
	return p * pow(a % m, m - 2, m) % m
for _ in range(int(input())):
	matrix = [[0 for i in range(9)] for i in range(9)]
	for i in range(9):
		a = input()
		for j in range(9):
			matrix[i][j] = a[j]
	matrix[2][0] = matrix[2][1]
	matrix[1][3] = matrix[1][4]
	matrix[0][6] = matrix[0][7]
	matrix[5][2] = matrix[5][0]
	matrix[4][5] = matrix[4][3]
	matrix[3][8] = matrix[3][6]
	matrix[8][1] = matrix[8][2]
	matrix[7][4] = matrix[7][5]
	matrix[6][7] = matrix[6][8]
	for i in matrix:
		print(''.join(i))


from statistics import mode
T = int(input())
for _ in range(T):
	arr = []
	for i in range(9):
		k = input()
		k = [x for x in k]
		arr.append(k)
	arr[0][8] = arr[0][7]
	arr[1][5] = arr[1][4]
	arr[2][2] = arr[2][1]
	arr[3][7] = arr[3][6]
	arr[4][4] = arr[4][3]
	arr[5][1] = arr[5][0]
	arr[6][6] = arr[6][7]
	arr[7][3] = arr[7][4]
	arr[8][0] = arr[8][1]
	for i in range(9):
		for j in range(9):
			print(arr[i][j], end='')
		print()


t = int(input())
for i in range(t):
	s = []
	for j in range(9):
		s.append(input())
	special = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	ans = []
	for row in range(9):
		temp = ''
		for col in range(9):
			if (row, col) not in special:
				temp += s[row][col]
			elif s[row][col] == '9':
				temp += '1'
			else:
				temp += '9'
		ans.append(temp)
	for i in range(9):
		print(ans[i])


for test in range(int(input())):
	change = [8, 4, 0, 1, 3, 6, 7, 5, 2]
	ans = []
	for i in range(9):
		arr = list(input())
		curr = int(arr[change[i]])
		if curr > 1:
			arr[change[i]] = str(curr - 1)
		else:
			arr[change[i]] = str(curr + 1)
		ans.append(''.join(arr))
	for i in ans:
		print(i)


def ans(board):
	for i in range(len(board)):
		for j in range(len(board[i])):
			if board[i][j] == 2:
				board[i][j] = 1
t = int(input())
for i in range(t):
	board = []
	for i in range(9):
		row = [int(x) for x in input()]
		board.append(row)
	ans(board)
	for i in board:
		print(''.join([str(x) for x in i]))


import math
alph = 'abcdefghijklmnopqrstuvwxyz'
t = int(input())
for _ in range(t):
	field = []
	for i in range(9):
		field.append(list(str(input())))
	field[0][0] = min(9, (int(field[0][0]) + 5) % 10 + 1)
	field[1][3] = min(9, (int(field[1][3]) + 5) % 10 + 1)
	field[2][6] = min(9, (int(field[2][6]) + 5) % 10 + 1)
	field[3][1] = min(9, (int(field[3][1]) + 5) % 10 + 1)
	field[4][4] = min(9, (int(field[4][4]) + 5) % 10 + 1)
	field[5][7] = min(9, (int(field[5][7]) + 5) % 10 + 1)
	field[6][2] = min(9, (int(field[6][2]) + 5) % 10 + 1)
	field[7][5] = min(9, (int(field[7][5]) + 5) % 10 + 1)
	field[8][8] = min(9, (int(field[8][8]) + 5) % 10 + 1)
	for i in range(9):
		for j in range(9):
			print(field[i][j], end='')
		print()


import math
from sys import stdin
for _ in range(int(input())):
	n = 9
	l = []
	for i in range(n):
		st = input()
		l1 = []
		for j in range(n):
			l1.append(int(st[j]))
		l.append(l1)
	a = [[0, 6], [1, 1], [2, 5], [3, 8], [4, 2], [5, 4], [6, 7], [7, 0], [8, 3]]
	for i in range(n):
		(j, k) = (a[i][0], a[i][1])
		if l[j][k] == 1:
			l[j][k] = 2
		else:
			l[j][k] = 1
	for i in range(n):
		for j in range(n):
			print(l[i][j], end='')
		print()


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 7
for _ in range(int(ri())):
	lis = []
	for i in range(9):
		s = ri()
		temp = [i for i in s]
		lis.append(temp)
	y = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	x = [0, 1, 2, 3, 4, 5, 6, 7, 8]
	for i in range(9):
		val = int(lis[x[i]][y[i]])
		val = (val + 1) % 9
		if val == 0:
			val = 9
		lis[x[i]][y[i]] = val
	for i in lis:
		print(''.join(map(str, i)))


def solve(board):
	result = []
	for row in board:
		row = row.replace('2', '1')
		result.append(row)
	return result
t = int(input())
for _ in range(t):
	board = []
	for _ in range(9):
		board.append(input())
	result = solve(board)
	for row in result:
		print(row)


from math import ceil

def solve():
	t = int(input())
	numbers = {x for x in range(1, 10)}
	for _ in range(t):
		s = [[] for _ in range(9)]
		for i in range(9):
			s[i] = list(map(int, input()))
		(x, y) = (0, 0)
		ok = numbers - {s[x][y]}
		s[x][y] = ok.pop()
		(x, y) = (1, 3)
		ok = numbers - {s[x][y]}
		s[x][y] = ok.pop()
		(x, y) = (2, 6)
		ok = numbers - {s[x][y]}
		s[x][y] = ok.pop()
		(x, y) = (3, 1)
		ok = numbers - {s[x][y]}
		s[x][y] = ok.pop()
		(x, y) = (4, 7)
		ok = numbers - {s[x][y]}
		s[x][y] = ok.pop()
		(x, y) = (5, 5)
		ok = numbers - {s[x][y]}
		s[x][y] = ok.pop()
		(x, y) = (6, 2)
		ok = numbers - {s[x][y]}
		s[x][y] = ok.pop()
		(x, y) = (7, 4)
		ok = numbers - {s[x][y]}
		s[x][y] = ok.pop()
		(x, y) = (8, 8)
		ok = numbers - {s[x][y]}
		s[x][y] = ok.pop()
		st = ''
		for i in s:
			st += ''.join(map(str, i)) + '\n'
		print(st.strip())
solve()


cases = int(input())
i = 0
cont = []

def convert():
	for i in range(0, 9):
		cont = sdk[i]
		index = 0
		numb = 0
		for j in range(0, 9):
			numb = numb * 10 + cont[index]
			index = index + 1
		print(numb)

def solver():
	if sdk[0][0] == 1:
		key1 = 3
		key2 = 2
	else:
		key1 = 1
		key2 = 3
	if sdk[0][0] == key1:
		sdk[0][0] = key2
	else:
		sdk[0][0] = key1
	if sdk[8][8] == key1:
		sdk[8][8] = key2
	else:
		sdk[8][8] = key1
	if sdk[5][7] == key1:
		sdk[5][7] = key2
	else:
		sdk[5][7] = key1
	if sdk[7][5] == key1:
		sdk[7][5] = key2
	else:
		sdk[7][5] = key1
	if sdk[4][4] == key1:
		sdk[4][4] = key2
	else:
		sdk[4][4] = key1
	if sdk[2][6] == key1:
		sdk[2][6] = key2
	else:
		sdk[2][6] = key1
	if sdk[1][3] == key1:
		sdk[1][3] = key2
	else:
		sdk[1][3] = key1
	if sdk[6][2] == key1:
		sdk[6][2] = key2
	else:
		sdk[6][2] = key1
	if sdk[3][1] == key1:
		sdk[3][1] = key2
	else:
		sdk[3][1] = key1
	convert()
row = [0, 0, 0, 0, 0, 0, 0, 0, 0]
sdk = [[0 for i in range(0, 9)] for j in range(0, 9)]
while i < cases:
	for p in range(0, 9):
		val = int(input())
		ind = 8
		for x in range(0, 9):
			row[ind] = val % 10
			val = int(val / 10)
			ind = ind - 1
		for j in range(0, 9):
			sdk[p][j] = row[j]
	solver()
	i = i + 1


t = int(input())
for you in range(t):
	lo = []
	for i in range(9):
		l = input()
		li = [int(i) for i in l]
		lo.append(li)
	for i in range(9):
		for j in range(9):
			if lo[i][j] != 9:
				print(lo[i][j], end='')
			else:
				print(1, end='')
		print()


for _ in range(int(input())):
	for _ in range(9):
		output = ''
		for elem in input():
			if elem == '1':
				output += '2'
			else:
				output += elem
		print(output)


t = int(input())
ans = []
for _ in range(t):
	mat = []
	for i in range(9):
		mat.append(list(map(int, input())))
	mat[0][0] = mat[0][0] % 9 + 1
	mat[3][1] = mat[3][1] % 9 + 1
	mat[6][2] = mat[6][2] % 9 + 1
	mat[1][3] = mat[1][3] % 9 + 1
	mat[4][4] = mat[4][4] % 9 + 1
	mat[7][5] = mat[7][5] % 9 + 1
	mat[2][6] = mat[2][6] % 9 + 1
	mat[5][7] = mat[5][7] % 9 + 1
	mat[8][8] = mat[8][8] % 9 + 1
	ans.append(mat)
for i in ans:
	for k in i:
		for j in k:
			print(j, end='')
		print()
	print()


for _ in range(int(input())):
	for x in range(3):
		for y in range(3):
			a = list(input())
			i = x + y * 3
			b = (int(a[i]) + 1) % 10
			a[i] = b if b != 0 else 1
			print(*a, sep='')


for _ in range(int(input())):
	sud = []
	for i in range(9):
		sud.append(input())
	temp1 = sud[0][1] + sud[0][1:]
	temp2 = sud[1][:3] + sud[1][4] + sud[1][4:]
	temp3 = sud[2][:6] + sud[2][7] + sud[2][7:]
	temp4 = sud[3][0] + sud[3][2] + sud[3][2:]
	temp5 = sud[4][:4] + sud[4][5] + sud[4][5:]
	temp6 = sud[5][:7] + sud[5][8] + sud[5][8]
	temp7 = sud[6][:2] + sud[6][3] + sud[6][3:]
	temp8 = sud[7][:5] + sud[7][6] + sud[7][6:]
	temp9 = sud[8][:8] + sud[8][7]
	new_sud = [temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9]
	for i in new_sud:
		print(i)


t = int(input())
for i in range(t):
	r = []
	for j in range(9):
		r.append(list(input()))
	r[0][0] = str(int(r[0][0]) % 9 + 1)
	r[1][3] = str(int(r[1][3]) % 9 + 1)
	r[2][6] = str(int(r[2][6]) % 9 + 1)
	r[3][1] = str(int(r[3][1]) % 9 + 1)
	r[4][4] = str(int(r[4][4]) % 9 + 1)
	r[5][7] = str(int(r[5][7]) % 9 + 1)
	r[6][2] = str(int(r[6][2]) % 9 + 1)
	r[7][5] = str(int(r[7][5]) % 9 + 1)
	r[8][8] = str(int(r[8][8]) % 9 + 1)
	for j in range(9):
		print(''.join(r[j]))


import sys
from math import sqrt, floor, ceil
from collections import deque, Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().split()))

def a():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		res = abs(n - 1 - ceil(n / 2) + n % 2)
		ans += str(res) + '\n'
	print(ans)

def b():
	ans = ''
	alph = 'abcdefghijklmnopqrstuvwxyz'
	for _ in range(int(inp())):
		(n, a, b) = read()
		seq = alph[:b] + alph[:b] * ((a - b) // b) + alph[:b][:(a - b) % b]
		res = seq * (n // a) + seq[:n % a]
		ans += res + '\n'
	print(ans)

def c():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		arr = read()
		uniq = len(set(arr))
		c = Counter(arr)
		mi = min(uniq, c.most_common()[0][1]) - (uniq == c.most_common()[0][1])
		ans += str(mi) + '\n'
	print(ans)

def d():
	ans = ''
	for _ in range(int(inp())):
		sud = []
		sett = set()
		for i in range(9):
			sud.append(list(inp().strip()))
		lis = [[0, 0], [1, 3], [2, 6], [3, 1], [4, 4], [5, 7], [6, 2], [7, 5], [8, 8]]
		for i in lis:
			(x, y) = i
			p = sud[x][y]
			sud[x][y] = str(9 - int(p) if p != '9' else 1)
		for i in sud:
			print(''.join(i))
d()


for _ in range(int(input())):
	lis = []
	for _ in range(9):
		lis.append([int(i) for i in list(input())])
	for (i, j) in zip([1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 4, 7, 2, 5, 8, 3, 6, 9]):
		lis[i - 1][j - 1] = 2 if lis[i - 1][j - 1] == 1 else lis[i - 1][j - 1] - 1
	[print(*i, sep='') for i in lis]


for j in range(int(input())):
	for i in range(9):
		l = list(input())
		l[i % 3 * 3 + i // 3] = l[(i % 3 * 3 + i // 3 + 1) % 9]
		print(''.join(l))


import math
t = int(input())
for i in range(t):
	ans = []
	for j in range(9):
		c = list(input())
		for k in range(9):
			if c[k] == '5':
				c[k] = '6'
		for h in c:
			print(h, end='')
		print()


t = int(input())
points = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
for testcase in range(t):
	sudoku = []
	for i in range(9):
		add = input()
		sudoku.append(list(add))
	counter = 0
	ans = ''
	while ans == '':
		cnt = {}
		for point in points:
			x = point[0]
			y = (point[1] + counter) % 9
			if sudoku[x][y] in cnt.keys():
				cnt[sudoku[x][y]] += 1
			else:
				cnt[sudoku[x][y]] = 1
		for i in range(1, 10):
			if str(i) not in cnt.keys():
				ans = str(i)
				break
		counter += 1
	counter -= 1
	for point in points:
		x = point[0]
		y = (point[1] + counter) % 9
		sudoku[x][y] = ans
	for i in sudoku:
		for j in i:
			print(j, end='')
		print()


T = int(input())
for i in range(T):
	for i in range(9):
		string = input()
		print(string.replace('3', '4'))


for _ in range(int(input())):
	a = []
	for _ in range(9):
		m = input()
		ll = [int(i) for i in m]
		a.append(list(ll))
	ll = [(0, 0), (1, 4), (2, 8), (3, 1), (4, 5), (5, 6), (6, 2), (7, 3), (8, 7)]
	for i in ll:
		(r, c) = (i[0], i[1])
		if a[r][c] == 9:
			a[r][c] = 1
			continue
		a[r][c] += 1
	for i in range(9):
		print(''.join(map(str, a[i])))


t = int(input())
for _ in range(t):
	su = []
	for i in range(9):
		a = input()
		a = list(a)
		su.append(a)
	for i in range(9):
		for j in range(9):
			if su[i][j] == '2':
				su[i][j] = '1'
	for i in range(len(su)):
		print(''.join(su[i]))


import sys

def printGrid():
	global grid
	for row in grid:
		for char in row:
			sys.stdout.write(str(char))
		sys.stdout.write('\n')
tests = int(input())
rows = []
for test in range(tests):
	for i in range(0, 9):
		rows.append(input())
grid = []
for row in rows:
	grid.append([int(char) for char in row.rstrip()])
pos = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
for test in range(tests):
	for (row, col) in pos:
		_row = row + test * 9
		_col = col
		if grid[_row][_col] + 1 == 10:
			grid[_row][_col] = 1
		else:
			grid[_row][_col] = grid[_row][_col] + 1
printGrid()


for _ in range(int(input())):
	for i in range(3):
		for j in range(3):
			t = input()
			n = []
			[n.append(i) for i in t]
			if i == 2 and j == 2:
				n[8] = n[0]
			else:
				n[3 * j + i] = n[3 * j + i + 1]
			print(''.join(n))


t = int(input())
for i in range(0, t):
	for j in range(0, 9):
		x = input().replace('1', '2')
		print(x)


for _ in range(int(input())):
	mat = []
	for i in range(9):
		row = input()
		row = row.replace('9', '1')
		mat.append(row)
	for x in mat:
		print(x)


for i in range(int(input())):
	for j in range(9):
		s = input()
		s = s[:j // 3 + j % 3 * 3] + s[(j // 3 + j % 3 * 3 + 1) % 9] + s[j // 3 + j % 3 * 3 + 1:]
		print(s)


t = int(input())
alphabets = ['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']
for testcase in range(t):
	for i in range(9):
		s = str(input())
		s = s.replace('2', '1')
		print(s)


for i in range(int(input())):
	se = {'1', '2', '3', '4', '5', '6', '7', '8', '9'}
	lis = []
	for i in range(9):
		lis.append(input())
	j = 0
	for i in range(9):
		if j >= 9:
			j = j % 9 + 1
		for z in se:
			if z != lis[i][j]:
				lis[i] = lis[i][:j] + z + lis[i][j + 1:]
				j += 3
				break
	for i in lis:
		print(i)


t = int(input())
for x in range(t):
	for i in range(9):
		sudoku = input()
		print(sudoku.replace('6', '2'))


def read():
	return [input() for _ in range(3 * 3)]

def solve(sudoku):
	offset = 0
	result = []
	for (idx, line) in enumerate(sudoku):
		block = offset % 3
		lvl = idx // 3
		change_idx = lvl + block * 3
		change = (int(line[change_idx]) + 1) % 9
		change = str(max(change, 1))
		result.append(line[:change_idx] + change + line[change_idx + 1:])
		offset += 1
	return '\n'.join(result)
for _ in range(int(input())):
	print(solve(read()))


t = int(input())
for l in range(t):
	g = []
	for i in range(9):
		k = input()
		g.append([])
		for ele in k:
			g[i].append(int(ele))
	i = 0
	j = 0
	while i < 9:
		if j >= 9:
			j = j % 9 + 1
		m = (g[i][j] + 1) % 10
		if m == 0:
			m += 1
		g[i][j] = m
		i += 1
		j += 3
	for i in range(9):
		for j in range(9):
			print(g[i][j], end='')
		print()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	grid = []
	for i in range(9):
		grid.append(list(input())[:-1])
	for i in range(9):
		for j in range(9):
			if grid[i][j] == '1':
				grid[i][j] = '2'
	for i in range(9):
		print(''.join(grid[i]))


t = int(input())
for i in range(t):
	s = []
	for j in range(9):
		s1 = list(input())
		s.append(s1)
	k = 0
	while k < 3:
		i = 3 * k
		j = k
		for c in range(3):
			if j != 8:
				s[i][j] = s[i][j + 1]
			else:
				s[i][j] = s[i][j - 1]
			i += 1
			j += 3
		k += 1
	for l in range(9):
		s2 = ''.join(s[l])
		print(s2)


t = int(input())
for i in range(t):
	matrix = []
	for j in range(9):
		matrix.append([int(s) for s in input()])
	coords = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for coord in coords:
		if matrix[coord[0]][coord[1]] == 9:
			matrix[coord[0]][coord[1]] = 1
		else:
			matrix[coord[0]][coord[1]] += 1
	for j in range(9):
		print(''.join((str(s) for s in matrix[j])))


t = int(input())
for lpv in range(t):
	a = [[0 for x in range(9)] for y in range(9)]
	for i in range(9):
		s = input()
		for j in range(9):
			a[i][j] = int(s[j])
	a[0][6] = a[0][5]
	a[1][1] = a[1][0]
	a[2][5] = a[2][8]
	a[3][8] = a[3][5]
	a[4][2] = a[4][0]
	a[5][4] = a[5][7]
	a[6][7] = a[6][6]
	a[7][0] = a[7][1]
	a[8][3] = a[8][2]
	for i in range(9):
		for j in range(9):
			print(a[i][j], sep='', end='')
		print()


import sys
input = sys.stdin.readline
swaps = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
t = int(input())
for j in range(t):
	sudoku = []
	for i in range(9):
		inp = input().strip()
		sudoku.append([int(k) for k in inp])
	for (a, b) in swaps:
		sudoku[a][b] = sudoku[a][b] % 9 + 1
	out = ''
	for i in range(9):
		out += ''.join((str(k) for k in sudoku[i]))
		out += '\n'
	print(out.strip())


t = int(input())
for _ in range(t):
	gr = [[int(i) for i in input()] for i in range(9)]
	for i in range(9):
		if i == 8:
			gr[i][8] += 1
			if gr[8][8] == 10:
				gr[8][8] = 1
			continue
		gr[i][i * 3 % 8] += 1
		if gr[i][i * 3 % 8] == 10:
			gr[i][i * 3 % 8] = 1
	for i in gr:
		print(*i, sep='')


for i in range(int(input())):
	result = []
	for j in range(9):
		l1 = list(input())
		a = l1.index('2')
		l1[a] = '1'
		result.append(l1)
	for k in range(9):
		print(''.join(result[k]))


def solve():
	a = []
	for i in range(9):
		aa = list(map(int, list(input())))
		a.append(aa)
	row = 0
	for o in range(3):
		for i in [0, 3, 6]:
			idx = i + o
			a[row][idx] = (a[row][idx] + 1) % 9 + 1
			row += 1
	print('\n'.join([''.join(map(str, aa)) for aa in a]))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


t = int(input())
for j in range(t):
	for i in range(9):
		a = str(input())
		b = []
		ans = ''
		for w in range(9):
			b.append(a[w])
		b[b.index('1')] = '2'
		for w in range(9):
			ans += b[w]
		print(ans)


from sys import stdin, stdout
dic = {0: 0, 1: 3, 2: 6, 3: 1, 4: 4, 5: 7, 6: 2, 7: 5, 8: 8}
t = int(input())
for _ in range(t):
	for i in range(9):
		a = list(input())
		index = dic[i]
		if int(a[index]) == 1:
			a[index] = str(2)
		else:
			a[index] = str(int(a[index]) - 1)
		print(''.join(a))


t = int(input())

def change(A, i, j):
	if A[i][j] == 9:
		A[i][j] = 1
	else:
		A[i][j] = 9
for _ in range(t):
	A = []
	for i in range(9):
		A.append(list(map(int, list(input()))))
	change(A, 0, 0)
	change(A, 1, 3)
	change(A, 2, 6)
	change(A, 3, 1)
	change(A, 4, 4)
	change(A, 5, 7)
	change(A, 6, 2)
	change(A, 7, 5)
	change(A, 8, 8)
	for row in A:
		print(''.join(list(map(str, row))))


for _ in range(int(input())):
	sud = [[] for _ in range(9)]
	for i in range(9):
		sud[i] = list(map(int, list(input())))
	for i in range(9):
		for j in range(9):
			if sud[i][j] == 2:
				sud[i][j] = 1
	for i in range(9):
		print(''.join(map(str, sud[i])))


t = int(input())
for i in range(t):
	a = []
	for j in range(9):
		s = list(input())
		ind = 3 * j % 9 + int(j / 3)
		if s[ind] == '1':
			s[ind] = '3'
		else:
			s[ind] = '1'
		for h in s:
			print(h, end='')
		print()


def solution():
	for i in range(9):
		s = list(input())
		for j in range(9):
			if s[j] == '1':
				s[j] = '2'
		s = ''.join(s)
		print(s)
for _ in range(int(input())):
	solution()


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def case():
	a = []
	for i in range(9):
		s = input().strip()
		s = list(s)
		a.append(s)
	for i in range(9):
		for j in range(9):
			if a[i][j] == '9':
				a[i][j] = '1'
		print(''.join(map(str, a[i])))
for _ in range(int(input())):
	case()


t = int(input())
place = [[0, 0], [1, 3], [2, 7], [3, 5], [4, 1], [5, 8], [6, 6], [7, 4], [8, 2]]
for i in range(t):
	soduku = []
	for j in range(9):
		soduku.append([int(s) for s in input()])
	for (j, k) in place:
		if soduku[j][k] == 1:
			soduku[j][k] = 9
		else:
			soduku[j][k] -= 1
	for j in range(9):
		print(''.join([str(k) for k in soduku[j]]))


t = int(input())
for q in range(t):
	l = []
	for i in range(9):
		l.append(list(input()))
	for i in range(0, 9, 3):
		for j in range(0, 9, 3):
			if l[i + j // 3][j + i // 3] == '1':
				l[i + j // 3][j + i // 3] = '9'
			else:
				l[i + j // 3][j + i // 3] = str(int(l[i + j // 3][j + i // 3]) - 1)
	for i in range(9):
		print(''.join(l[i]))


import sys
q = int(input())
for t in range(q):
	for i in range(9):
		tmp = input()
		print(tmp.replace('9', '1'))


def cv(s):
	n = []
	for i in range(len(s)):
		n.append(int(s[i]))
	return n
t = int(input())
for i in range(t):
	a = [cv(input()) for _ in range(9)]
	a[0][0] = (a[0][0] + 1) % 9 + 1
	a[3][1] = (a[3][1] + 1) % 9 + 1
	a[6][2] = (a[6][2] + 1) % 9 + 1
	a[1][3] = (a[1][3] + 1) % 9 + 1
	a[4][4] = (a[4][4] + 1) % 9 + 1
	a[7][5] = (a[7][5] + 1) % 9 + 1
	a[2][6] = (a[2][6] + 1) % 9 + 1
	a[5][7] = (a[5][7] + 1) % 9 + 1
	a[8][8] = (a[8][8] + 1) % 9 + 1
	for j in a:
		print(*j, sep='')


t = int(input())
for _ in range(t):
	for i in range(9):
		soduku = input()
		print(soduku.replace('1', '2'))


from random import randint

def solve(A):
	k = 0
	for i in range(3):
		A[i][k] = 1 if A[i][k] != 1 else 2
		k += 3
	k = 1
	for i in range(3, 6):
		A[i][k] = 1 if A[i][k] != 1 else 2
		k += 3
	k = 2
	for i in range(6, 9):
		A[i][k] = 1 if A[i][k] != 1 else 2
		k += 3
	return A
n = 9
for _ in range(int(input())):
	A = [list(map(int, input())) for _ in range(n)]
	[print(*x, sep='') for x in solve(A)]


t = int(input())
while t > 0:
	for i in range(9):
		s = input()
		for j in range(9):
			c = s[j]
			if c == '1':
				c = '2'
			print(c, end='')
		print()
	t = t - 1


for _ in range(int(input())):
	l = []
	for i in range(9):
		s = input()
		l1 = []
		for j in s:
			l1.append(int(j))
		l.append(l1)
	a = l[0][0]
	if a == 9:
		l[0][0] = 1
	else:
		l[0][0] = a + 1
	a = l[1][3]
	if a == 9:
		l[1][3] = 1
	else:
		l[1][3] = a + 1
	a = l[2][6]
	if a == 9:
		l[2][6] = 1
	else:
		l[2][6] = a + 1
	a = l[4][1]
	if a == 9:
		l[4][1] = 1
	else:
		l[4][1] = a + 1
	a = l[5][4]
	if a == 9:
		l[5][4] = 1
	else:
		l[5][4] = a + 1
	a = l[3][7]
	if a == 9:
		l[3][7] = 1
	else:
		l[3][7] = a + 1
	a = l[8][2]
	if a == 9:
		l[8][2] = 1
	else:
		l[8][2] = a + 1
	a = l[6][5]
	if a == 9:
		l[6][5] = 1
	else:
		l[6][5] = a + 1
	a = l[7][8]
	if a == 9:
		l[7][8] = 1
	else:
		l[7][8] = a + 1
	for i in range(9):
		x = l[i]
		for j in x:
			print(j, end='')
		print(end='\n')


t = int(input())
for I in range(t):
	board = []
	for _ in range(9):
		board.append([int(x) for x in input()])
	board[0][0] = board[0][0] % 9 + 1
	board[1][3] = board[1][3] % 9 + 1
	board[2][6] = board[2][6] % 9 + 1
	board[3][1] = board[3][1] % 9 + 1
	board[4][4] = board[4][4] % 9 + 1
	board[5][7] = board[5][7] % 9 + 1
	board[6][2] = board[6][2] % 9 + 1
	board[7][5] = board[7][5] % 9 + 1
	board[8][8] = board[8][8] % 9 + 1
	for row in board:
		for col in row:
			print(col, end='')
		print()


t = int(input())
ans = []
while t:
	t -= 1
	for i in range(9):
		s = input()
		if i == 0:
			s = s[1] + s[1:9]
		elif i == 1:
			s = s[0:4] + s[3] + s[5:9]
		elif i == 2:
			s = s[0:8] + s[7]
		elif i == 3:
			s = s[0] + s[0] + s[2:9]
		elif i == 4:
			s = s[0:5] + s[4] + s[6:9]
		elif i == 5:
			s = s[0:7] + s[6] + s[8]
		elif i == 6:
			s = s[0:2] + s[1] + s[3:9]
		elif i == 7:
			s = s[0:3] + s[2] + s[4:9]
		elif i == 8:
			s = s[0:6] + s[5] + s[7:9]
		print(s)


from collections import defaultdict
changes = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
t = int(input())
for _ in range(t):
	sudoku = [list(input()) for _ in range(9)]
	for change in changes:
		sudoku[change[0]][change[1]] = str(int(sudoku[change[0]][change[1]]) % 9 + 1)
	for line in sudoku:
		print(''.join(line))


from sys import stdin
inp = stdin.readline
t = int(inp().strip())
for _ in range(t):
	soduko = []
	for i in range(9):
		soduko.append([int(x) for x in str(inp().strip())])
	for i in range(9):
		for j in range(9):
			if soduko[i][j] == 1:
				soduko[i][j] = 2
	for i in range(9):
		print(''.join(map(str, soduko[i])))


for _ in range(int(input())):
	q = []
	for i in range(9):
		l = list(input())
		if i == 0:
			l[0] = l[-1]
		elif i == 1:
			l[3] = l[-1]
		elif i == 2:
			l[6] = l[-1]
		elif i == 3:
			l[1] = l[-1]
		elif i == 4:
			l[4] = l[-1]
		elif i == 5:
			l[7] = l[-1]
		elif i == 6:
			l[2] = l[-1]
		elif i == 7:
			l[5] = l[-1]
		else:
			l[8] = l[0]
		for i in range(9):
			print(l[i], end='')
		print()


t = int(input())
import math
delay = []
for _ in range(t):
	a = []
	for _ in range(9):
		a.append(list(input()))
	a[0][0] = str((1 + int(a[0][0])) % 9 + 1)
	a[1][3] = str((1 + int(a[1][3])) % 9 + 1)
	a[2][6] = str((1 + int(a[2][6])) % 9 + 1)
	a[3][1] = str((1 + int(a[3][1])) % 9 + 1)
	a[5][7] = str((1 + int(a[5][7])) % 9 + 1)
	a[4][4] = str((1 + int(a[4][4])) % 9 + 1)
	a[6][2] = str((1 + int(a[6][2])) % 9 + 1)
	a[7][5] = str((1 + int(a[7][5])) % 9 + 1)
	a[8][8] = str((1 + int(a[8][8])) % 9 + 1)
	for i in a:
		print(''.join(i))


for _ in range(int(input())):
	str2 = ''
	for i in range(9):
		str1 = input()
		for i in str1:
			if i == '1':
				str2 += '2'
			else:
				str2 += i
	for i in range(0, 81, 9):
		print(str2[i:i + 9])


for _ in range(int(input())):
	arr = []
	for i in range(9):
		s = input()
		s = s.replace('1', '2')
		arr.append(s)
	for i in arr:
		print(i)


def split(word):
	return [char for char in word]
t = int(input())
for i in range(0, t):
	sudoku = []
	for i in range(0, 9):
		b = input()
		sudoku.append(split(b))
	if sudoku[0][0] == '1':
		sudoku[0][0] = 2
	else:
		sudoku[0][0] = 1
	if sudoku[3][1] == '1':
		sudoku[3][1] = 2
	else:
		sudoku[3][1] = 1
	if sudoku[6][2] == '1':
		sudoku[6][2] = 2
	else:
		sudoku[6][2] = 1
	if sudoku[1][3] == '1':
		sudoku[1][3] = 2
	else:
		sudoku[1][3] = 1
	if sudoku[4][4] == '1':
		sudoku[4][4] = 2
	else:
		sudoku[4][4] = 1
	if sudoku[5][7] == '1':
		sudoku[5][7] = 2
	else:
		sudoku[5][7] = 1
	if sudoku[2][6] == '1':
		sudoku[2][6] = 2
	else:
		sudoku[2][6] = 1
	if sudoku[7][5] == '1':
		sudoku[7][5] = 2
	else:
		sudoku[7][5] = 1
	if sudoku[8][8] == '1':
		sudoku[8][8] = 2
	else:
		sudoku[8][8] = 1
	for i in range(0, 9):
		for j in range(0, 9):
			print(sudoku[i][j], end='')
		print('\t')


from sys import stdin

def solve(d):
	k = set([(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)])
	for i in range(9):
		for j in range(9):
			if (i, j) in k:
				g = (ord(d[i][j]) - ord('0') + 1) % 9 + 1
				print(g, end='')
			else:
				print(d[i][j], end='')
		print()
	return

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		d = []
		for i in range(9):
			h = inp().strip()
			d.append(h)
		solve(d)
main()


t = int(input())
while t:
	t -= 1
	s = []
	for i in range(9):
		s += [list(input())]
	s[0][0] = s[0][1]
	s[1][3] = s[1][4]
	s[2][6] = s[2][7]
	s[3][1] = s[3][2]
	s[4][4] = s[4][5]
	s[5][7] = s[5][8]
	s[6][2] = s[6][3]
	s[7][5] = s[7][6]
	s[8][8] = s[8][0]
	for ss in s:
		print(''.join(ss))


t = int(input())
for ii in range(t):
	array = []
	for i in range(9):
		array.append(list(input()))
	x = 0
	y = 0
	temp = {}
	for i in range(1, 10):
		temp[str(i)] = str(i + 1)
	temp['9'] = temp['1']
	for i in range(9):
		array[x][y] = temp[array[x][y]]
		y += 1
		x += 3
		if y == 3:
			x = 1
		if y == 6:
			x = 2
	for i in array:
		print(''.join(i))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	for _ in range(N()):
		arr = []
		for _ in range(9):
			arr.append(list(input()))
		arr[0][0] = arr[0][1]
		arr[1][3] = arr[1][4]
		arr[2][6] = arr[2][7]
		arr[3][1] = arr[3][2]
		arr[4][4] = arr[4][5]
		arr[5][7] = arr[5][8]
		arr[6][2] = arr[6][1]
		arr[7][5] = arr[7][4]
		arr[8][8] = arr[8][7]
		for i in arr:
			print(''.join(i))
main()


import sys
input = sys.stdin.readline
MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input().strip('\n'))
si = lambda : input().strip('\n')
dgl = lambda : list(map(int, input().strip('\n')))
f = lambda : map(int, input().strip('\n').split())
il = lambda : list(map(int, input().strip('\n').split()))
ls = lambda : list(input().strip('\n'))
let = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(ii()):
	sud = []
	for i in range(9):
		s = ls()
		sud.append(s)
	sud[1][3] = '1' if sud[1][3] != '1' else '2'
	sud[0][0] = '1' if sud[0][0] != '1' else '2'
	sud[2][6] = '1' if sud[2][6] != '1' else '2'
	sud[3][1] = '1' if sud[3][1] != '1' else '2'
	sud[4][4] = '1' if sud[4][4] != '1' else '2'
	sud[5][7] = '1' if sud[5][7] != '1' else '2'
	sud[6][2] = '1' if sud[6][2] != '1' else '2'
	sud[7][5] = '1' if sud[7][5] != '1' else '2'
	sud[8][8] = '1' if sud[8][8] != '1' else '2'
	for i in sud:
		print(''.join(i))


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
res = ['YES', 'NO']
let = [chr(i) for i in range(97, 123)]

def main():
	a = []
	for i in range(9):
		a.append(lsi())
	j = -1
	for i in range(9):
		if not i % 3:
			j += 1
		k = j + 3 * (i % 3)
		z = int(a[i][k])
		z -= 1
		if not z:
			z = 9
		a[i][k] = str(z)
	for i in a:
		print(*i, sep='')
	return
for _ in range(ii()):
	main()


for _ in range(int(input())):
	m = []
	for i in range(9):
		r = [ch for ch in input()]
		m.append(r)
	c = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
	for (y, x) in c:
		if x + 1 < 9:
			m[y][x] = m[y][x + 1]
		else:
			m[y][x] = m[y][x - 1]
	for i in range(9):
		print(''.join(map(str, m[i])))


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def solve(lst):
	pos = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for i in pos:
		if lst[i[0]][i[1]] == '1':
			lst[i[0]][i[1]] = str(int(lst[i[0]][i[1]]) + 1)
		else:
			lst[i[0]][i[1]] = str(int(lst[i[0]][i[1]]) - 1)
	return lst
for _ in range(int(input())):
	lst = []
	for i in range(9):
		lst.append(list(input()))
	lst1 = solve(lst)
	for i in lst1:
		print(''.join(i))


for _ in range(int(input())):
	sudo = []
	for _ in range(9):
		sudo.append(input())
	for line in sudo:
		print(line.replace('2', '1'))


for _ in range(int(input())):
	matrix = []
	for i in range(9):
		row = list(map(int, list(input())))
		matrix.append(row)
	taken_columns = set()
	taken_rows = set()
	taken_block = set()
	for i in range(9):
		for j in range(9):
			current_row = i
			current_column = j
			current_block = 3 * (i // 3) + j // 3
			if current_row not in taken_rows and current_column not in taken_columns and (current_block not in taken_block):
				matrix[i][j] = matrix[i][3 * (j // 3) + (j % 3 + 1) % 3]
				taken_rows.add(current_row)
				taken_columns.add(current_column)
				taken_block.add(current_block)
	print()
	for i in range(9):
		for j in range(9):
			print(matrix[i][j], end='')
		print()


import sys
import os
from io import BytesIO, IOBase

def cel(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
for _ in range(ii()):
	a = [0 for i in range(9)]
	for i in range(9):
		a[i] = list(input())
	tmp = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		if a[i][tmp[i]] != '5':
			a[i][tmp[i]] = str(10 - int(a[i][tmp[i]]))
		else:
			a[i][tmp[i]] = '4'
	for i in range(9):
		print(''.join(a[i]))


for _ in ' ' * int(input()):
	for _ in ' ' * 9:
		print(input().replace('9', '1'))


test = int(input())
for i in range(test):
	mx = []
	for i in range(9):
		num = input()
		res = [int(x) for x in num]
		mx.append(res)
	for i in range(9):
		for j in range(9):
			if mx[i][j] == 1:
				mx[i][j] = 2
	for i in range(9):
		for j in range(9):
			print(mx[i][j], end='')
		print()


t = int(input())
for i in range(t):
	out = []
	for i in range(9):
		inp = [i for i in input()]
		out.append(inp)
	for i in range(3):
		for j in range(3):
			out[i + 3 * j][3 * i + j] = '9' if out[i + 3 * j][3 * i + j] != '9' else '8'
	for i in out:
		print(''.join(i))


t = int(input())
while t:
	for i in range(9):
		a = input()
		for i in a:
			if i == '1':
				print('2', end='')
			else:
				print(i, end='')
		print()
	t -= 1


import sys
from collections import *
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for test in range(t):
	A = [list(input()) for i in range(9)]
	A[0][0] = A[0][1]
	A[1][3] = A[1][4]
	A[2][6] = A[2][7]
	A[3][1] = A[3][0]
	A[4][4] = A[4][3]
	A[5][7] = A[5][6]
	A[6][2] = A[6][1]
	A[7][5] = A[7][4]
	A[8][8] = A[8][7]
	A = [''.join(a) for a in A]
	print('\n'.join(A))


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

def ls():
	return list(map(int, list(input())))

def i():
	return int(input())
t = i()
for __ in range(t):
	a = []
	for _ in range(9):
		a.append(ls())
	a[6][2] = a[6][0]
	a[7][5] = a[7][3]
	a[8][8] = a[8][6]
	a[0][0] = a[0][1]
	a[1][3] = a[1][4]
	a[2][6] = a[2][7]
	a[3][1] = a[3][2]
	a[4][4] = a[4][5]
	a[5][7] = a[5][8]
	for i in range(9):
		print(''.join(list(map(str, a[i]))))


t = int(input())
for i in range(t):
	a = []
	for j in range(9):
		a.append(list(input()))
	ind = 0
	for j in range(9):
		if a[j][ind] == '1':
			a[j][ind] = '2'
		else:
			a[j][ind] = '1'
		if j == 2:
			ind = 1
		elif j == 5:
			ind = 2
		else:
			ind += 3
	for el in a:
		print(''.join(el))


t = int(input())
for _ in range(t):
	so = []
	for i in range(9):
		d = str(input())
		s = []
		for i in d:
			s.append(int(i))
		so.append(s)
	ij = [(1, 1), (2, 4), (3, 7), (4, 2), (5, 5), (6, 8), (7, 3), (8, 6), (9, 9)]
	for (i, j) in ij:
		a = i - 1
		b = j - 1
		if so[a][b] == 5:
			so[a][b] = 1
		else:
			so[a][b] = 5
	for i in range(9):
		ans = ''
		for j in range(9):
			ans += str(so[i][j])
		print(ans)


try:
	t = int(input())
	for _ in range(t):
		A = []
		for i in range(9):
			A.append(list(input()))
		A[0][6] = A[0][5]
		A[1][1] = A[1][0]
		A[2][5] = A[2][8]
		A[3][8] = A[3][5]
		A[4][2] = A[4][0]
		A[5][4] = A[5][7]
		A[6][7] = A[6][6]
		A[7][0] = A[7][1]
		A[8][3] = A[8][2]
		for i in range(9):
			print(''.join(A[i]))
except:
	pass


t = int(input())
for i in range(t):
	a = []
	c = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	for i in range(9):
		a.append(str(input()))
	for i in range(9):
		if int(a[i][c[i]]) < 9:
			print(int(a[i].replace(str(a[i][c[i]]), str(int(a[i][c[i]]) + 1))))
		else:
			print(int(a[i].replace(str(a[i][c[i]]), str(int(a[i][c[i]]) - 1))))


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		l = []
		for i in range(9):
			l.append(list(si()))
		p = [0] * 10
		q = [0] * 10
		x = []
		x.append(int(l[0][0]))
		x.append(int(l[3][1]))
		x.append(int(l[6][2]))
		for j in range(9):
			if j + 1 not in x:
				l[0][0] = j + 1
				l[3][1] = j + 1
				l[6][2] = j + 1
				break
		x = []
		x.append(int(l[1][3]))
		x.append(int(l[4][4]))
		x.append(int(l[7][5]))
		for j in range(9):
			if j + 1 not in x:
				l[1][3] = j + 1
				l[4][4] = j + 1
				l[7][5] = j + 1
				break
		x = []
		x.append(int(l[2][6]))
		x.append(int(l[5][7]))
		x.append(int(l[8][8]))
		for j in range(9):
			if j + 1 not in x:
				l[2][6] = j + 1
				l[5][7] = j + 1
				l[8][8] = j + 1
				break
		for i in range(9):
			for j in range(9):
				print(l[i][j], end='')
			print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, exit
from collections import Counter
input = stdin.readline

def i():
	return input()

def ii():
	return int(input())

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

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

def print_array(a):
	print(''.join(map(str, a)))

def get_set_column(sudoku, col):
	cs = set()
	for i in range(len(sudoku)):
		if i == col:
			continue
		cs.add(sudoku[i][col])
	return cs

def get_set_square(sudoku, pos):
	ss = set()
	i = pos - pos % 3
	for j in range(i, i + 3):
		for k in range(i, i + 3):
			if j == k:
				continue
			ss.add(sudoku[j][k])
	return ss

def get_number(sl, sc, ss):
	for i in ss:
		if i in sc:
			if i in sl:
				return i
t = ii()
for _ in range(t):
	sudoku = []
	for i in range(9):
		line = input()
		linea = [c for c in line.strip()]
		sudoku.append(linea)
	j = 0
	for i in range(len(sudoku)):
		set_line = set(sudoku[j])
		set_line.discard(sudoku[j][i])
		set_column = get_set_column(sudoku, i)
		set_square = get_set_square(sudoku, i)
		found = get_number(set_line, set_column, set_square)
		sudoku[j][i] = found
		j += 3
		if j > 8:
			j = j % 9 + 1
	for i in sudoku:
		print_array(i)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import itertools
t = int(input())

def ch(offset):
	for (A, B, C) in itertools.permutations([0, 1, 2]):
		if li[3 * offset + A][offset] != li[3 * offset + B][3 + offset] and li[3 * offset + A][offset] != li[3 * offset + C][6 + offset] and (li[3 * offset + C][6 + offset] != li[3 * offset + B][3 + offset]):
			(li[3 * offset + A][offset], li[3 * offset + B][3 + offset], li[3 * offset + C][6 + offset]) = (li[3 * offset + C][6 + offset], li[3 * offset + A][offset], li[3 * offset + B][3 + offset])
			break
for _ in range(t):
	li = []
	for __ in range(9):
		li.append(list(input()))
	ch(0)
	ch(1)
	ch(2)
	for j in li:
		print(''.join(j))


import sys
import string
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	A = []
	for z in range(9):
		A.append([int(x) for x in input()])
	change = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for (i, j) in change:
		if A[i][j] == 9:
			A[i][j] = 1
		else:
			A[i][j] += 1
	for a in A:
		print(int(''.join(map(str, a))))


t = int(input())
while t:
	l1 = []
	for p in range(0, 9):
		str1 = input()
		l3 = list(str1)
		for i in range(0, 9):
			l3[i] = int(l3[i])
		l1.append(l3)
	l2 = [0, 4, 8, 1, 5, 6, 2, 3, 7]
	for i in range(0, 9):
		if l1[i][l2[i]] < 9:
			l1[i][l2[i]] = l1[i][l2[i]] + 1
		else:
			l1[i][l2[i]] = 1
	for m in range(0, 9):
		for k in range(0, 9):
			print(l1[m][k], end='')
		print()
	t = t - 1


t = int(input())
while t:
	t -= 1
	c = -1
	for i in range(9):
		if i % 3 == 0:
			c += 1
		s = input()
		print(s[:c] + str((int(s[c]) + 1) % 9 + 1) + s[c + 1:])
		c += 3
		c %= 9


tmp = [0, 3, 6, 1, 4, 7, 2, 5, 8]
t = int(input())
for i in range(t):
	for j in range(9):
		s = input()
		a = int(s[tmp[j]])
		a = a % 9 + 1
		s2 = ''
		for k in range(9):
			if k != tmp[j]:
				s2 += s[k]
			else:
				s2 += str(a)
		print(s2)


t = int(input())
for i in range(t):
	for i in range(9):
		line = input()
		if line[i % 3 * 3 + i // 3] == '9':
			line = line[:i % 3 * 3 + i // 3] + '1' + line[i % 3 * 3 + i // 3 + 1:]
		else:
			line = line[:i % 3 * 3 + i // 3] + str(int(line[i % 3 * 3 + i // 3]) + 1) + line[i % 3 * 3 + 1 + i // 3:]
		print(line)


for _ in range(int(input())):
	for i in range(9):
		row = input()
		for ch in row:
			if ch == '2':
				print('1', end='')
			else:
				print(ch, end='')
		print()


for l in range(int(input())):
	print(*[input().replace('2', '1') for i in range(9)], sep='\n')


t = int(input())
for _ in range(t):
	lst = [list(map(int, list(input()))) for i in range(9)]
	ans = [(0, 0), (3, 1), (1, 3), (4, 4), (2, 6), (6, 2), (5, 7), (7, 5), (8, 8)]
	for i in ans:
		if lst[i[0]][i[1]] == 5:
			lst[i[0]][i[1]] = 4
		else:
			lst[i[0]][i[1]] = 10 - lst[i[0]][i[1]]
	print('\n'.join([''.join([str(i) for i in j]) for j in lst]))


def getOtherElement(e):
	if e < '9':
		return chr(ord(e) + 1)
	else:
		return '1'
t = int(input())
testcaseList = []
for testcaseIndex in range(t):
	puzzle = []
	for rowIndex in range(9):
		row = list(input())
		puzzle.append(row)
	testcaseList.append(puzzle)
for puzzle in testcaseList:
	puzzle[0][0] = getOtherElement(puzzle[0][0])
	puzzle[1][3] = getOtherElement(puzzle[1][3])
	puzzle[2][6] = getOtherElement(puzzle[2][6])
	puzzle[3][1] = getOtherElement(puzzle[3][1])
	puzzle[4][4] = getOtherElement(puzzle[4][4])
	puzzle[5][7] = getOtherElement(puzzle[5][7])
	puzzle[6][2] = getOtherElement(puzzle[6][2])
	puzzle[7][5] = getOtherElement(puzzle[7][5])
	puzzle[8][8] = getOtherElement(puzzle[8][8])
	for row in puzzle:
		print(''.join(row))


import math
from collections import Counter

def solve():
	l1 = []
	for i in range(9):
		l1.append(list(input()))
	for i in range(9):
		v = l1[i].index('1')
		if v < 3:
			l1[i][(v + 1) % 3] = '1'
		elif v < 6:
			l1[i][3 + (v + 1) % 3] = '1'
		else:
			l1[i][6 + (v + 1) % 3] = '1'
	for i in range(9):
		for j in range(9):
			print(l1[i][j], end='')
		print()
for _ in range(int(input())):
	solve()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	field = []
	for i in range(9):
		line = [int(item) for item in input().rstrip()]
		field.append(line)
	j = 0
	for i in range(9):
		if field[i][j] != 9:
			field[i][j] += 1
		else:
			field[i][j] = 1
		if i % 3 == 2:
			j += 4
		else:
			j += 3
		j %= 9
	for line in field:
		print(''.join([str(item) for item in line]))


for _ in range(int(input())):
	arr = []
	for i in range(9):
		arr.append(input())
	ans = []
	z = 0
	j = 0
	while j < 9:
		k = z
		for i in range(3):
			if z == 2:
				ans.append(arr[j][:k] + arr[j][k - 1] + arr[j][k + 1:])
			else:
				ans.append(arr[j][:k] + arr[j][k + 1] + arr[j][k + 1:])
			k += 3
			j += 1
		z += 1
	for i in range(9):
		print(ans[i])


for qq in range(int(input())):
	s = [list(input()) for i in range(9)]
	if s[0][0] == '9':
		s[0][0] = '1'
	else:
		s[0][0] = chr(ord(s[0][0]) + 1)
	if s[3][1] == '9':
		s[3][1] = '1'
	else:
		s[3][1] = chr(ord(s[3][1]) + 1)
	if s[6][2] == '9':
		s[6][2] = '1'
	else:
		s[6][2] = chr(ord(s[6][2]) + 1)
	if s[1][3] == '9':
		s[1][3] = '1'
	else:
		s[1][3] = chr(ord(s[1][3]) + 1)
	if s[4][4] == '9':
		s[4][4] = '1'
	else:
		s[4][4] = chr(ord(s[4][4]) + 1)
	if s[7][5] == '9':
		s[7][5] = '1'
	else:
		s[7][5] = chr(ord(s[7][5]) + 1)
	if s[2][6] == '9':
		s[2][6] = '1'
	else:
		s[2][6] = chr(ord(s[2][6]) + 1)
	if s[5][7] == '9':
		s[5][7] = '1'
	else:
		s[5][7] = chr(ord(s[5][7]) + 1)
	if s[8][8] == '9':
		s[8][8] = '1'
	else:
		s[8][8] = chr(ord(s[8][8]) + 1)
	for i in s:
		print(*i, sep='')


for t in range(int(input())):
	sudoku = list()
	indices = [0, 13, 26, 28, 41, 51, 56, 66, 79]
	for _ in range(9):
		sudoku += list(map(int, list(input())))
	for i in indices:
		if sudoku[i] == 9:
			sudoku[i] -= 1
		else:
			sudoku[i] += 1
	for i in range(9):
		print(''.join((str(x) for x in sudoku[i * 9:(i + 1) * 9])))


t = int(input())
for _ in range(t):
	for i in range(3):
		a = input()
		b = 3 * i + 1
		print(a[:b] + a[b - 1] + a[b + 1:])
	for i in range(3):
		a = input()
		b = 3 * i + 2
		print(a[:b] + a[b - 1] + a[b + 1:])
	for i in range(3):
		a = input()
		b = 3 * i
		print(a[:b] + a[b + 2] + a[b + 1:])


for test in range(int(input())):
	for j in range(9):
		st = input()
		st = st.replace('9', '1')
		print(st)


t = int(input())
l = [1, 4, 7, 2, 5, 8, 3, 6, 9]
for i in range(t):
	ans = []
	for i in range(len(l)):
		s = input()
		nums = []
		for char in s:
			nums.append(int(char))
		nums[l[i] - 1] = (int(nums[l[i] - 1]) + 1) % 9 + 1
		print(''.join((str(n) for n in nums)))


for _ in range(int(input())):
	for i in range(9):
		j = 4 * i % 9
		s = list(input())
		s[j] = int(s[j]) % 9 + 1
		print(*s, sep='')


from math import *
t = int(input())
output = []
for _ in range(t):
	g = []
	for i in range(9):
		g.append(list(input()))
	for i in range(0, 9):
		z = -1
		if i < 3:
			z = 0
		elif i < 6:
			z = 1
		else:
			z = 2
		a = int(g[3 * i % 9 + z][i])
		if a == 9:
			g[3 * i % 9 + z][i] = '1'
		else:
			g[3 * i % 9 + z][i] = '9'
	output.append(g)
for g in output:
	for l in g:
		s = ''
		for c in l:
			s += c
		print(s)


from math import *
from bisect import bisect_left, bisect_right
from queue import Queue
from sys import stdin, stdout
from collections import Counter
input = lambda : stdin.readline().strip()
fast_print = stdout.write
t = int(input())
for _ in range(t):
	ls = []
	for i in range(9):
		ls.append(list(map(int, list(input()))))
	ls[0][0] = 9 if ls[0][0] != 9 else 8
	ls[3][1] = 9 if ls[3][1] != 9 else 8
	ls[6][2] = 9 if ls[6][2] != 9 else 8
	ls[1][3] = 9 if ls[1][3] != 9 else 8
	ls[4][4] = 9 if ls[4][4] != 9 else 8
	ls[7][5] = 9 if ls[7][5] != 9 else 8
	ls[2][6] = 9 if ls[2][6] != 9 else 8
	ls[5][7] = 9 if ls[5][7] != 9 else 8
	ls[8][8] = 9 if ls[8][8] != 9 else 8
	for i in range(9):
		for j in range(9):
			fast_print(str(ls[i][j]))
		fast_print('\n')


for _ in range(int(input())):
	l = []
	n = 9
	for _ in range(n):
		l.append(input())
	change = 0
	j = 0
	k = 0
	arr = [0, 3, 6, 1, 4, 7, 2, 5, 8]
	i = arr[k]
	while change < 9:
		if int(l[i][j]) == 9:
			val = 1
		else:
			val = int(l[i][j]) + 1
		l[i] = l[i][:j] + str(val) + l[i][j + 1:]
		j += 1
		change += 1
		k += 1
		if k == 9:
			break
		i = arr[k]
	for i in range(9):
		print(l[i])


NUM_ITR = int(input())
for iteration in range(NUM_ITR):
	c = 0
	for i in range(9):
		strli = input()
		for j in range(9):
			if j == c:
				newNum = int(strli[j]) + 1
				if newNum > 9:
					newNum = 1
				print(newNum, end='')
			else:
				print(strli[j], end='')
		c = (c + 3) % 8
		if c == 0:
			c = 8
		print()


for t in range(int(input())):
	board = []
	for i in range(9):
		board.append(list(input()))
	for i in range(9):
		for j in range(9):
			if board[i][j] == '2':
				board[i][j] = '1'
	for i in range(9):
		for j in range(9):
			print(board[i][j], end='')
		print()


t = int(input())
for _ in range(t):
	arr = []
	for __ in range(9):
		arr.append([int(x) for x in input()])
	arr[0][0] = arr[0][1]
	arr[3][1] = arr[3][2]
	arr[6][2] = arr[6][1]
	arr[1][3] = arr[1][4]
	arr[4][4] = arr[4][5]
	arr[7][5] = arr[7][4]
	arr[2][6] = arr[2][7]
	arr[5][7] = arr[5][8]
	arr[8][8] = arr[8][6]
	for r in arr:
		print(''.join([str(x) for x in r]))


t = int(input())
for i in range(t):
	for j in range(9):
		a = int(input())
		a = str(a)
		k = a.find('1', 0, 9)
		b = a[0:k] + '2' + a[k + 1:9]
		print(b)


for ii in range(int(input())):
	b = []
	for jj in range(9):
		a = str(input())
		b.append(list(a))
	c = []
	for i in range(9):
		for j in range(9):
			if b[i][j] == '1':
				c.append([i, j])
	for i in c:
		b[i[0]][i[1]] = '2'
	for i in range(9):
		print(''.join(b[i]))


t = int(input())
for i in range(t):
	inp = [input() for j in range(9)]
	s = [[] for j in range(9)]
	for j in range(9):
		for k in range(9):
			s[j].append(inp[j][k])
	for j in range(3):
		for k in range(3):
			if k < 2:
				s[3 * j + k][3 * k + j] = s[3 * j + k + 1][3 * k + j]
			else:
				s[3 * j + k][3 * k + j] = s[3 * j + k - 1][3 * k + j]
	for j in range(9):
		for k in range(9):
			print(s[j][k], end='')
		print()


t = int(input())
pts = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
for _ in range(t):
	matrix = [list(input()) for _ in range(9)]
	for (x, y) in pts:
		matrix[x][y] = str(int(matrix[x][y]) % 9 + 1)
	for row in matrix:
		print(''.join(row))


from sys import stdin
import math
inp = stdin.readline
t = int(inp().strip())
while t:
	t -= 1
	line = []
	for i in range(9):
		line.append(list(inp().strip()))
	line[0][0] = line[0][1]
	line[1][4] = line[1][5]
	line[2][8] = line[2][6]
	line[3][1] = line[3][2]
	line[4][5] = line[4][3]
	line[5][6] = line[5][7]
	line[6][2] = line[6][0]
	line[7][3] = line[7][4]
	line[8][7] = line[8][8]
	for i in range(9):
		print(*line[i], sep='')


for i in range(int(input())):
	s = [[i for i in input()] for i in range(9)]
	cnt = 0
	j = 1
	for i in range(9):
		if cnt >= 9:
			cnt = j
			j += 1
		if s[i][cnt] != '9':
			s[i][cnt] = str(int(s[i][cnt]) + 1)
		else:
			s[i][cnt] = '1'
		cnt += 3
	for i in s:
		print(''.join(i))


def solve():
	f = [[int(j) for j in input()] for i in range(9)]
	for i in range(9):
		for j in range(9):
			print(max(f[i][j], 2), end='')
		print()
t = int(input())
while t > 0:
	solve()
	t -= 1


def main():
	tc_count = int(input())
	for tc in range(tc_count):
		mp = []
		for i in range(9):
			mp.append([c for c in input()])
		for i in range(9):
			for j in range(9):
				if mp[i][j] == '1':
					mp[i][j] = '2'
			print(''.join(mp[i]))
main()


T = int(input())
for t in range(T):
	M = []
	for i in range(9):
		riga = list(input())
		M.append(riga)
	S = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for s in S:
		if M[s[0]][s[1]] == '1':
			M[s[0]][s[1]] = '2'
		else:
			M[s[0]][s[1]] = '1'
	for i in range(9):
		s = ''
		for j in range(9):
			s = s + M[i][j]
		print(s)


from sys import stdout
t = int(input())
for _ in range(t):
	i = 0
	for _ in range(9):
		for ch in input():
			stdout.write('1' if ch == '2' else ch)
		stdout.write('\n')


t = int(input())
c = []
for k in range(t):
	a = []
	rez = []
	for i in range(9):
		rez.append('')
	for i in range(9):
		a.append(input())
	for i in range(9):
		for j in range(9):
			if i == 0 and j == 0 or (i == 1 and j == 3) or (i == 2 and j == 6) or (i == 3 and j == 1) or (i == 4 and j == 4) or (i == 5 and j == 7) or (i == 6 and j == 2) or (i == 7 and j == 5):
				rez[i] += a[i][j + 1]
			elif i == 8 and j == 8:
				rez[i] += a[i][j - 1]
			else:
				rez[i] += a[i][j]
	c.append(rez)
for i in range(t):
	for j in range(9):
		print(c[i][j])


import sys

def solve():
	T = int(input())
	for t in range(T):
		m = []
		for i in range(9):
			m.append([n for n in list(input())])
		for i in range(9):
			for j in range(9):
				if m[i][j] == '2':
					m[i][j] = '1'
		for row in m:
			print(''.join(row))
solve()


cord = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5)]
T = int(input())
for t in range(T):
	A = []
	for i in range(9):
		a = list(input())
		A.append(a)
	for each in cord:
		x = each[0]
		y = each[1]
		A[x][y] = A[x][y + 1]
	A[8][8] = A[8][7]
	for p in A:
		for o in p:
			print(o, end='')
		print()


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

def mult_input():
	return map(int, input().split())
for nt in range(int(input())):
	matrix = []
	for i in range(9):
		s = input()
		matrix.append(list(s))
	ans = [[-1 for i in range(9)] for j in range(9)]
	for i in range(9):
		for j in range(9):
			if j == i % 3 * 3 + i // 3:
				if i % 3 == 0:
					ans[i][j] = matrix[i + 1][j]
				else:
					ans[i][j] = matrix[i - 1][j]
			else:
				ans[i][j] = matrix[i][j]
	for i in range(9):
		for j in range(9):
			print(ans[i][j], end='')
		print()


for t in range(int(input())):
	l = []
	for i in range(9):
		s = input()
		a = []
		for j in s:
			a.append(j)
		l.append(a)
	c = 0
	k = 0
	for i in range(9):
		if i == 0:
			l[i][0] = l[i][1]
		if i == 1:
			l[i][3] = l[i][4]
		if i == 2:
			l[i][6] = l[i][7]
		if i == 3:
			l[i][1] = l[i][2]
		if i == 4:
			l[i][4] = l[i][5]
		if i == 5:
			l[i][7] = l[i][8]
		if i == 6:
			l[i][2] = l[i][3]
		if i == 7:
			l[i][5] = l[i][6]
		if i == 8:
			l[i][8] = l[i][0]
	for i in range(9):
		for j in range(9):
			print(l[i][j], end='')
		print()


import sys

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip()
		q[i] = [int(x) for x in q[i]]
	for i in range(1, len(q)):
		for j in range(len(q[i])):
			if q[i][j] == 3:
				q[i][j] = 1
		q[i] = [str(x) for x in q[i]]
		print(''.join(q[i]))
main()


for _ in range(int(input())):
	m = [list(input()) for i in range(9)]
	m[0][0] = str(int(m[0][0]) % 9 + 1)
	m[1][3] = str(int(m[1][3]) % 9 + 1)
	m[2][6] = str(int(m[2][6]) % 9 + 1)
	m[3][1] = str(int(m[3][1]) % 9 + 1)
	m[4][4] = str(int(m[4][4]) % 9 + 1)
	m[5][7] = str(int(m[5][7]) % 9 + 1)
	m[6][2] = str(int(m[6][2]) % 9 + 1)
	m[7][5] = str(int(m[7][5]) % 9 + 1)
	m[8][8] = str(int(m[8][8]) % 9 + 1)
	for i in m:
		print(''.join(i))


for m in range(int(input())):
	a = []
	for i in range(9):
		a.append(list(input()))
	for i in range(9):
		for j in range(9):
			if a[i][j] == '1':
				a[i][j] = '2'
	for i in a:
		print(''.join(i))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	s = []
	for i in range(3):
		for j in range(3):
			a = input()
			a = list(a)
			if int(a[3 * j + i]) == 5:
				a[3 * j + i] = '1'
			else:
				a[3 * j + i] = '5'
			s.append(''.join(a))
	for i in range(9):
		print(s[i])


tests = int(input())
values = [[0] * 9 for x in range(tests)]
for i in range(tests):
	for k in range(9):
		values[i][k] = input()
		values[i][k] = values[i][k].replace('1', '2')
for i in range(tests):
	for k in range(9):
		print(values[i][k])


from sys import stdin, stdout
for testcases in range(int(stdin.readline())):
	sudoku = []
	for i in range(9):
		a = stdin.readline()
		b = []
		for i in range(9):
			b.append(int(a[i]))
		sudoku.append(b)
	sudoku[0][0] = sudoku[1][0]
	sudoku[1][3] = sudoku[2][3]
	sudoku[2][6] = sudoku[1][6]
	sudoku[3][1] = sudoku[4][1]
	sudoku[4][4] = sudoku[5][4]
	sudoku[5][7] = sudoku[4][7]
	sudoku[6][2] = sudoku[7][2]
	sudoku[7][5] = sudoku[8][5]
	sudoku[8][8] = sudoku[7][8]
	for i in range(9):
		for j in range(9):
			print(sudoku[i][j], end='')
		print()


I = lambda : list(map(int, input().split()))
import collections as cc
te = [[1, 1], [2, 4], [3, 7], [4, 2], [5, 5], [6, 8], [7, 3], [8, 6], [9, 9]]
for tc in range(int(input())):
	a = []
	for i in range(9):
		x = list(input())
		a.append(x)
	for i in te:
		(x, y) = i
		x -= 1
		y -= 1
		v = int(a[x][y])
		vv = (v + 1) % 9
		if vv == 0:
			vv += 1
		a[x][y] = str(vv)
	for i in a:
		print(''.join(i))


t = int(input())
q = [0, 3, 6, 1, 4, 7, 2, 5, 8]
for nfjg in range(0, t):
	for i in range(0, 9):
		z = list(input())
		if z[q[i]] == '1':
			z[q[i]] = '2'
		else:
			z[q[i]] = '1'
		d = ''.join(z)
		print(d)


def inter(n, i):
	for m in range(1, 10):
		if str(m) != n[i]:
			d = n[:i] + str(m) + n[i + 1:]
			break
	return d
test = int(input())
for t in range(test):
	L = []
	x = 1
	y = 2
	for i in range(9):
		n = str(input())
		if i in [0, 1, 2]:
			L.append(inter(n, 3 * i))
		elif i in [3, 4, 5]:
			L.append(inter(n, x))
			x += 3
		else:
			L.append(inter(n, y))
			y += 3
	for x in L:
		print(x)


tc = int(input())
while tc > 0:
	t = [list(input()) for i in range(9)]
	a = [0, 4, 8, 1, 5, 6, 2, 3, 7]
	for i in range(len(a)):
		j = a[i]
		t[i][j] = '1' if t[i][j] == '9' else chr(ord(t[i][j]) + 1)
	for l in t:
		print(''.join(l))
	tc -= 1


a = int(input())
for x in range(a):
	k = []
	for y in range(9):
		d = input()
		p = []
		for z in range(9):
			p.append(d[z])
		k.append(p)
	k[0][0] = k[0][1]
	k[1][3] = k[1][4]
	k[2][6] = k[2][7]
	k[3][1] = k[3][2]
	k[4][4] = k[4][5]
	k[5][7] = k[5][8]
	k[6][2] = k[6][0]
	k[7][5] = k[7][3]
	k[8][8] = k[8][6]
	for y in range(9):
		for z in range(9):
			print(k[y][z], end='')
		print()


const = '147258369'
for x in range(int(input())):
	mains = ''
	for y in range(9):
		index = int(const[y]) - 1
		row = list(input())
		if row[index] == '9':
			row[index] = '1'
		else:
			row[index] = str(int(row[index]) + 1)
		mains += ''.join(row) + '\n'
	print(mains)


import sys
input = sys.stdin.readline
t = int(input())
from collections import Counter
for _ in range(t):
	a = [list(input().rstrip()) for _ in range(9)]
	l = 0
	r = 0
	for i in range(3):
		for (j, k) in zip(range(l, l + 3), range(r, r + 7, 3)):
			if int(a[j][k]) < 9:
				a[j][k] = str(int(a[j][k]) + 1)
			else:
				a[j][k] = str(1)
		l += 3
		r += 1
	for i in a:
		print(''.join(i))


for lo in range(int(input())):
	ls = []
	for i in range(9):
		n = input()
		ls.append(n)
	for i in range(9):
		st = ls[i]
		a = i // 3
		b = i % 3
		j = 3 * b + a
		s = ''
		if i == 0:
			s = st[1] + st[1:9]
		else:
			s = st[:j] + st[j - 1] + st[j + 1:]
		print(int(s))


t = int(input())
for tc in range(t):
	a = [[int(i) for i in input()] for j in range(9)]
	b = [(0, 0), (1, 3), (2, 6), (3, 1), (4, 4), (5, 7), (6, 2), (7, 5), (8, 8)]
	for pt in b:
		tk = (7 if pt[0] == 8 else pt[0] + 1, pt[1])
		a[pt[0]][pt[1]] = a[tk[0]][tk[1]]
	for i in range(9):
		print(''.join(map(str, a[i])))


t = int(input())
for _ in range(t):
	s = [0] * 9
	for i in range(9):
		s[i] = str(input())
	for i in range(1, 10):
		if i != int(s[0][0]) and i != int(s[1][3]) and (i != int(s[2][6])):
			a = i
	for i in range(3):
		for i2 in range(9):
			if i == 0 and i2 == 0 or (i == 1 and i2 == 3) or (i == 2 and i2 == 6):
				print(a, end='')
			else:
				print(s[i][i2], end='')
		print('')
	for i in range(1, 10):
		if i != int(s[3][1]) and i != int(s[4][4]) and (i != int(s[5][7])):
			a = i
	for i in range(3, 6):
		for i2 in range(9):
			if i == 3 and i2 == 1 or (i == 4 and i2 == 4) or (i == 5 and i2 == 7):
				print(a, end='')
			else:
				print(s[i][i2], end='')
		print('')
	for i in range(1, 10):
		if i != int(s[6][2]) and i != int(s[7][5]) and (i != int(s[8][8])):
			a = i
	for i in range(6, 9):
		for i2 in range(9):
			if i == 6 and i2 == 2 or (i == 7 and i2 == 5) or (i == 8 and i2 == 8):
				print(a, end='')
			else:
				print(s[i][i2], end='')
		print('')


for _ in range(int(input())):
	a = []
	for i in range(9):
		b = list(input())
		a.append(b)
	k = 0
	for i in range(9):
		if i == 8:
			k = 8
		a[i][k] = str(int(a[i][k]) % 9 + 1)
		k = (k + 3) % 8
	for x in a:
		print(*x, sep='')


inp = lambda cast=int: [cast(x) for x in input().split()]
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
(t,) = inp()
for _ in range(t):
	A = []
	for i in range(9):
		A.append(list(inp(str)[0]))
	indices = [(0, 0), (3, 1), (6, 2), (1, 3), (4, 4), (7, 5), (2, 6), (5, 7), (8, 8)]
	for (x, y) in indices:
		A[x][y] = str(int(A[x][y]) % 9 + 1)
	for a in A:
		print(''.join(a))