Artem is building a new robot. He has a matrix $a$ consisting of $n$ rows and $m$ columns. The cell located on the $i$-th row from the top and the $j$-th column from the left has a value $a_{i,j}$ written in it. 

If two adjacent cells contain the same value, the robot will break. A matrix is called good if no two adjacent cells contain the same value, where two cells are called adjacent if they share a side. 

Artem wants to increment the values in some cells by one to make $a$ good.

More formally, find a good matrix $b$ that satisfies the following condition —   For all valid ($i,j$), either $b_{i,j} = a_{i,j}$ or $b_{i,j} = a_{i,j}+1$. 

For the constraints of this problem, it can be shown that such a matrix $b$ always exists. If there are several such tables, you can output any of them. Please note that you do not have to minimize the number of increments.


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows.

The first line of each test case contains two integers $n, m$ ($1 \le n \le 100$, $1 \le m \le 100$)  — the number of rows and columns, respectively.

The following $n$ lines each contain $m$ integers. The $j$-th integer in the $i$-th line is $a_{i,j}$ ($1 \leq a_{i,j} \leq 10^9$).


-----Output-----

For each case, output $n$ lines each containing $m$ integers. The $j$-th integer in the $i$-th line is $b_{i,j}$.


-----Example-----
Input
3
3 2
1 2
4 5
7 8
2 2
1 1
3 3
2 2
1 3
2 2

Output
1 2
5 6
7 8
2 1
4 3
2 4
3 2



-----Note-----

In all the cases, you can verify that no two adjacent cells have the same value and that $b$ is the same as $a$ with some values incremented by one.

Difficulty: HARD
Tags: Constructive algorithms

Strong connectivity

Number theory

Flows and cuts

Polynomials and generating functions

Starter code:

Solutions:
def ic(n, a, s=0, st=1):
	return [a for i in range(s, n, st)]

def ri():
	return int(input())

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

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

def mati(n):
	return [ra() for i in range(n)]
for _ in range(int(input())):
	(n, m) = sa()
	a = mati(n)
	for i in range(n):
		for j in range(m):
			if (a[i][j] ^ i ^ j) & 1:
				a[i][j] += 1
		print(*a[i])


for i in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for j in range(n):
		a = list(map(int, input().split()))
		mat.append(a)
	counter = True
	for j in range(n):
		for k in range(m):
			if counter:
				if mat[j][k] % 2 != 0:
					mat[j][k] += 1
			elif mat[j][k] % 2 == 0:
				mat[j][k] += 1
			counter = not counter
		if m % 2 == 0:
			counter = not counter
	for j in range(n):
		print(*mat[j])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append([*map(int, input().split())])
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0 and a[i][j] % 2 != 0:
				a[i][j] += 1
			elif (i + j) % 2 != 0 and a[i][j] % 2 == 0:
				a[i][j] += 1
		print(*a[i])


t = int(input())
answers = []
for _ in range(t):
	nm = input().split()
	a = []
	b = []
	numbers = []
	for i in range(int(nm[0])):
		m = input().split()
		a_row = []
		for j in range(int(nm[1])):
			a_row.append(int(m[j]))
		a.append(a_row)
	for k in range(int(nm[0])):
		for n in range(int(nm[1])):
			if (k + n) % 2 == 0:
				if a[k][n] % 2 != 0:
					a[k][n] += 1
			elif a[k][n] % 2 == 0:
				a[k][n] += 1
	answers.append(a)
for l in range(t):
	answer = answers[l]
	for row in answer:
		print(' '.join(map(str, row)))


import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
from decimal import Decimal as BIGFLOAT
from typing import OrderedDict
from copy import deepcopy
mod = 1000000007
sys.setrecursionlimit(1000000)
try:
	sys.stdin = open('actext.txt', 'r')
	OPENFILE = 1
except:
	pass

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

def palindrome(s):
	mid = len(s) // 2
	for i in range(mid):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True

def check(i, n):
	if 0 <= i < n:
		return True
	else:
		return False
t = int(input())
for tt in range(t):
	(n, m) = get_ints()
	mat = []
	for i in range(n):
		mat.append(list(get_ints()))
	sc = 0
	for i in range(n):
		if i % 2 == 0:
			sc = 0
		else:
			sc = 1
		for j in range(m):
			if sc % 2 == 0 and mat[i][j] % 2 != 0:
				mat[i][j] += 1
			elif sc % 2 != 0 and mat[i][j] % 2 == 0:
				mat[i][j] += 1
			sc = 1 - sc
	for i in mat:
		print(*i)


import sys
input = sys.stdin.readline
t = int(input())
for cs in range(t):
	(n, m) = map(int, input().split())
	a = [[] for _ in range(n)]
	for i in range(n):
		a[i] = [int(_) for _ in input().split()]
		for j in range(m):
			if a[i][j] % 2 != (i + j) % 2:
				a[i][j] += 1
	print('\n'.join([' '.join(map(str, a[_])) for _ in range(n)]))


import sys
import math
from collections import defaultdict, Counter
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):
	(n, m) = map(int, input().split())
	for j in range(n):
		a = list(map(int, input().split()))
		for k in range(m):
			if j + k & 1 == a[k] & 1:
				a[k] += 1
		print(*a)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, m) = map(int, stdin.readline().split())
	arr = []
	for _ in range(n):
		arr.append(list(map(int, stdin.readline().split())))
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				if arr[i][j] % 2 == 0:
					continue
				else:
					arr[i][j] += 1
			elif arr[i][j] % 2 != 0:
				continue
			else:
				arr[i][j] += 1
	for i in range(n):
		for j in range(m):
			print(arr[i][j], end=' ')
		print('')


import sys, threading, os.path
import string
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def is_valid(i, j, n, m):
	return i >= 0 and j >= 0 and (i < n) and (j < m)

def main():
	if os.path.exists('in.txt'):
		input = open('in.txt', 'r')
	else:
		input = sys.stdin
	t = int(input.readline())
	results = []
	for i in range(t):
		(n, m) = list(map(int, input.readline().split()))
		matrix = []
		for j in range(n):
			lis = list(map(int, input.readline().split()))
			matrix.append(lis)
		for x in range(n):
			for y in range(0, m, 2):
				if matrix[x][y] % 2 == (x % 2 == 0) - 0:
					matrix[x][y] += 1
			for y in range(1, m, 2):
				if matrix[x][y] % 2 == 1 - (x % 2 == 0):
					matrix[x][y] += 1
		for lis in matrix:
			results.append(lis)
	output = '\n'.join((' '.join(map(str, re)) for re in results))
	if os.path.exists('out.txt'):
		open('out.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		k = list(map(int, input().split()))
		l.append(k)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != l[i][j] % 2:
				l[i][j] += 1
	for i in range(n):
		print(*l[i])


test = int(input())
for testCase in range(test):
	(n, m) = map(int, input().split())
	a = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0 and a[i][j] % 2 != 0:
				a[i][j] += 1
			elif (i + j) % 2 != 0 and a[i][j] % 2 == 0:
				a[i][j] += 1
		print(*a[i])


for _ in range(int(input())):
	(row, column) = map(int, input().split())
	grid = []
	for r in range(row):
		l = list(map(int, input().split()))
		grid.append(l)
	for r in range(row):
		for c in range(column):
			if (r + c) % 2 == 0:
				if grid[r][c] % 2 == 0:
					continue
				else:
					grid[r][c] += 1
			elif grid[r][c] % 2 == 1:
				continue
			else:
				grid[r][c] += 1
	for r in grid:
		print(*r)


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = inar()
		matrix = []
		for i in range(n):
			matrix.append(inar())
		for i in range(n):
			for j in range(m):
				if (i + j) % 2 == 0:
					if matrix[i][j] % 2 != 0:
						matrix[i][j] += 1
				elif matrix[i][j] % 2 != 1:
					matrix[i][j] += 1
		for i in range(n):
			print(*matrix[i])
main()


t = int(input())
for _ in range(t):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	l = []
	[l.append([int(k) for k in input().split()]) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0 and l[i][j] % 2 == 1 or ((i + j) % 2 == 1 and l[i][j] % 2 == 0):
				l[i][j] += 1
			print(l[i][j], end=' ')
		print()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		a = list(map(int, input().split()))
		arr.append(a)
	for i in range(n):
		for j in range(m):
			if i % 2 == 0:
				if j % 2 == 1 and arr[i][j] % 2 == 0:
					arr[i][j] += 1
				elif j % 2 == 0:
					if arr[i][j] % 2 == 1:
						arr[i][j] += 1
			elif j % 2 == 0 and arr[i][j] % 2 == 0:
				arr[i][j] += 1
			elif j % 2 == 1:
				if arr[i][j] % 2 == 1:
					arr[i][j] += 1
	for i in range(n):
		arr[i] = map(str, arr[i])
		print(' '.join(arr[i]))


import sys
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	for i in range(0, n, 2):
		for j in range(0, m, 2):
			if l[i][j] % 2 == 1:
				l[i][j] += 1
		for j in range(1, m, 2):
			if l[i][j] % 2 == 0:
				l[i][j] += 1
	for i in range(1, n, 2):
		for j in range(0, m, 2):
			if l[i][j] % 2 == 0:
				l[i][j] += 1
		for j in range(1, m, 2):
			if l[i][j] % 2 == 1:
				l[i][j] += 1
	for i in range(n):
		print(*l[i])


def solve(h, w, m):
	res = [[0] * w for _ in range(h)]
	for i in range(h):
		for j in range(w):
			next = m[i][j]
			if (i + j) % 2 == 0:
				res[i][j] = next + next % 2
			else:
				res[i][j] = next + (1 - next % 2)
	return res
t = int(input())
while t:
	(h, w) = map(int, input().split())
	res = []
	for _ in range(h):
		res.append(list(map(int, input().split())))
	k = solve(h, w, res)
	for x in k:
		print(*x)
	t -= 1


for nt in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	b = []
	for i in range(n):
		b.append([])
		for j in range(m):
			if a[i][j] % 2 != (i + j) % 2:
				b[-1].append(a[i][j] + 1)
			else:
				b[-1].append(a[i][j])
	for i in b:
		print(*i)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	for i in range(n):
		a = list(map(int, input().split()))
		for j in range(m):
			if (i + j) % 2 != a[j] % 2:
				a[j] += 1
		print(*a)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	rb = True
	for _ in range(n):
		row = list(map(int, input().split()))
		b = rb
		for (i, ri) in enumerate(row):
			if b and ri % 2 != 0 or (not b and ri % 2 == 0):
				ri += 1
			if i == m - 1:
				print(ri)
			else:
				print(ri, end=' ')
			b = not b
		rb = not rb


for _ in range(int(input())):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	l = []
	for i in range(n):
		a = [int(i) for i in input().split()]
		l.append(a)
	for i in range(len(l)):
		if i % 2 == 0:
			c = 0
			for j in range(len(l[i])):
				if j % 2 == 0:
					if l[i][j] % 2 == 0:
						l[i][j] += 1
				elif l[i][j] % 2 != 0:
					l[i][j] += 1
		else:
			for j in range(len(l[i])):
				if j % 2 != 0:
					if l[i][j] % 2 == 0:
						l[i][j] += 1
				elif l[i][j] % 2 != 0:
					l[i][j] += 1
	for i in l:
		for j in i:
			print(j, end=' ')
		print()


import sys
input = sys.stdin.readline

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

def inlt():
	return list(map(int, input().split()))
T = inp()
for _ in range(T):
	(n, m) = inlt()
	A = []
	for _ in range(n):
		row = inlt()
		A.append(row)
	for i in range(n):
		row = []
		for j in range(m):
			parity = (i + j) % 2
			if A[i][j] % 2 != parity:
				row.append(str(A[i][j] + 1))
			else:
				row.append(str(A[i][j]))
		print(' '.join(row))


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
t = int(input())
for _ in range(t):
	(n, m) = get_ints()
	a = []
	for i in range(n):
		a.append(get_ints())
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				if a[i][j] % 2 != 0:
					a[i][j] = a[i][j] + 1
			elif a[i][j] % 2 != 1:
				a[i][j] = a[i][j] + 1
	for i in range(n):
		print(*a[i])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	out = []
	t = 0
	for i in range(n):
		for j in range(m):
			if t % 2 == 0:
				if j % 2 == 0:
					if l[i][j] % 2 == 0:
						l[i][j] += 1
				elif l[i][j] % 2 != 0:
					l[i][j] += 1
			elif j % 2 == 0:
				if l[i][j] % 2 != 0:
					l[i][j] += 1
			elif l[i][j] % 2 == 0:
				l[i][j] += 1
		t += 1
	for i in range(n):
		print(*l[i])


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

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

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

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

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

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
for _ in range(II()):
	(h, w) = MI()
	aa = LLI(h)
	for i in range(h):
		for j in range(w):
			if aa[i][j] & 1 == i + j & 1:
				aa[i][j] += 1
	for row in aa:
		print(*row)


t = int(input())
for _ in range(t):
	(x, y) = [int(i) for i in input().split()]
	l = []
	for __ in range(x):
		l.append([int(i) for i in input().split()])
	for i in range(x):
		for j in range(y):
			if (i + j) % 2 == 0:
				if l[i][j] % 2 == 1:
					l[i][j] += 1
			elif l[i][j] % 2 == 0:
				l[i][j] += 1
	for i in range(x):
		for j in range(y):
			print(l[i][j], end=' ')
		print()


t = int(input())
for p in range(t):
	(n, m) = map(int, input().split())
	a = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (a[i][j] - i - j) % 2 != 0:
				a[i][j] += 1
		print(*a[i])


r = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, m) = r()
	[print(*(a + (a + i + j) % 2 for (j, a) in enumerate(r()))) for i in range(n)]


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()

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

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

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
sys.setrecursionlimit(100000)
for _ in range(N()):
	(n, m) = RL()
	g = []
	for _ in range(n):
		g.append(RLL())
	for i in range(n):
		for j in range(m):
			if g[i][j] & 1 != i + j & 1:
				g[i][j] += 1
	for line in g:
		print_list(line)


def solve(a):
	for i in range(n):
		for j in range(m):
			if (a[i][j] - i - j) % 2 == 1:
				a[i][j] += 1
	for i in range(n):
		print(' '.join(map(str, a[i])))
for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for j in range(n):
		a.append(list(map(int, input().split())))
	solve(a)


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	arr = []
	for i in range(n):
		temp = [int(x) for x in input().split()]
		arr.append(temp)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2:
				if arr[i][j] & 1:
					arr[i][j] += 1
			elif arr[i][j] % 2 == 0:
				arr[i][j] += 1
	for i in arr:
		for j in i:
			print(j, end=' ')
		print()


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(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

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

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

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

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 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 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	if y == 0:
		return 1
	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 swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

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

def union(x, y, link, size):
	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)]
	(prime[0], prime[1]) = (False, False)
	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

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.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)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

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

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

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

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

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(val, pair):
	summ = 0
	for x in pair:
		if x[1] > val:
			summ += x[0]
	return summ > val

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	(n, m) = read()
	a = [get_list() for i in range(n)]
	for i in range(n):
		for j in range(m):
			if i % 2 == 0 and j % 2 != a[i][j] % 2:
				a[i][j] += 1
			elif i % 2 == 1 and j % 2 == a[i][j] % 2:
				a[i][j] += 1
	for x in a:
		print(*x)
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')
t = scanner()
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [0] * n
	for i in range(n):
		a[i] = list(map(int, input().split()))
	for k in range(n):
		for l in range(m):
			if (k + l) % 2 == 0:
				if a[k][l] % 2 == 0:
					a[k][l] += 1
			elif a[k][l] % 2 != 0:
				a[k][l] += 1
	for j in range(n):
		print(*a[j])


def makeEven(num):
	if num & 1 == 1:
		num += 1
	return num

def makeOdd(num):
	if num & 1 == 0:
		num += 1
	return num
t = int(input())
for i in range(t):
	(n, m) = tuple(map(int, input().split()))
	mat = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		if i & 1 == 0:
			for j in range(m):
				if j & 1 == 0:
					mat[i][j] = makeEven(mat[i][j])
				else:
					mat[i][j] = makeOdd(mat[i][j])
		else:
			for j in range(m):
				if j & 1 == 0:
					mat[i][j] = makeOdd(mat[i][j])
				else:
					mat[i][j] = makeEven(mat[i][j])
	for r in range(n):
		print(' '.join([str(c) for c in mat[r]]))


for z in range(int(input())):
	(n, m) = map(int, input().split())
	A = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				if A[i][j] % 2 == 0:
					A[i][j] += 1
			elif A[i][j] % 2 == 1:
				A[i][j] += 1
			print(A[i][j], end=' ')
		print()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	matrix = []
	for _ in range(n):
		b = [int(x) for x in input().split()]
		matrix.append(b)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				if matrix[i][j] % 2 == 0:
					matrix[i][j] += 1
			elif (i + j) % 2 == 1:
				if matrix[i][j] % 2 == 1:
					matrix[i][j] += 1
			print(matrix[i][j], end=' ')
		print()


import sys
input = sys.stdin.readline
from itertools import groupby
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())

def HalfDead():
	a = []
	(n, m) = R()
	for i in range(n):
		a.append(L())
	for i in range(n):
		for j in range(m):
			if i + j & 1 and (not a[i][j] & 1):
				a[i][j] += 1
			if not i + j & 1 and a[i][j] & 1:
				a[i][j] += 1
	for i in range(n):
		print(*a[i])
for _ in range(I()):
	HalfDead()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		arr.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(m):
			if i + j & 1:
				if arr[i][j] & 1:
					arr[i][j] += 1
			elif not arr[i][j] & 1:
				arr[i][j] += 1
	for i in range(n):
		for j in range(m):
			print(arr[i][j], end=' ')
		print()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		la = list(map(int, input().split()))
		l.append(la)
	cnt = 0
	if l[0][0] % 2 != 0:
		l[0][0] += 1
	for i in range(n):
		for j in range(m):
			if i == 0 and j == 0:
				continue
			else:
				flag = 0
				if i - 1 >= 0 and l[i - 1][j] % 2 == 0 and (l[i][j] % 2 == 0) and (flag == 0):
					l[i][j] += 1
					flag = 1
				if j - 1 >= 0 and l[i][j - 1] % 2 == 0 and (l[i][j] % 2 == 0) and (flag == 0):
					l[i][j] += 1
					flag = 1
				if i - 1 >= 0 and l[i - 1][j] % 2 != 0 and (l[i][j] % 2 != 0) and (flag == 0):
					l[i][j] += 1
					flag = 1
				if j - 1 >= 0 and l[i][j - 1] % 2 != 0 and (l[i][j] % 2 != 0) and (flag == 0):
					l[i][j] += 1
					flag = 1
		cnt += 1
	for i in l:
		print(*i)


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(n, m) = map(int, stdin.readline().split())
	a = []
	for i in range(n):
		A = list(map(int, stdin.readline().split()))
		a.append(A)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != a[i][j] % 2:
				a[i][j] += 1
	for i in a:
		print(*i)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	matrix = [list(map(int, input().split())) for i in range(n)]
	for y in range(n):
		for x in range(m):
			if y % 2 == x % 2:
				if matrix[y][x] % 2 != 0:
					matrix[y][x] += 1
			elif matrix[y][x] % 2 == 0:
				matrix[y][x] += 1
	for y in matrix:
		for x in y:
			print(x, end=' ')
		print()


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		temp = list(map(int, input().split()))
		mat.append(temp)
	for i in range(n):
		for j in range(m):
			if mat[i][j] % 2 != (i + j) % 2:
				mat[i][j] += 1
	for i in range(n):
		print(*mat[i])


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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 RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [(ch, len(list(g))) for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = N()
for i in range(t):
	(n, m) = RL()
	arr = []
	for i in range(n):
		arr.append(RLL())
	for i in range(n):
		for j in range(m):
			if i + j & 1:
				if not arr[i][j] & 1:
					arr[i][j] += 1
			elif arr[i][j] & 1:
				arr[i][j] += 1
	for i in range(n):
		print(*arr[i])


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0 and arr[i][j] % 2 == 1:
				arr[i][j] += 1
			elif (i + j) % 2 == 1 and arr[i][j] % 2 == 0:
				arr[i][j] += 1
	for d in arr:
		print(' '.join(map(str, d)))


import sys

def input():
	return sys.stdin.readline()
dif = [(-1, 0), (1, 0), (0, 1), (0, -1)]

def solve():
	(m, n) = map(int, input().split())
	matrix = [list(map(int, input().split())) for i in range(m)]
	for i in range(m):
		for j in range(n):
			which = (i + j) % 2
			if which == 0:
				if matrix[i][j] % 2 != 0:
					matrix[i][j] += 1
			elif matrix[i][j] % 2 == 0:
				matrix[i][j] += 1
	for i in range(m):
		print(*matrix[i])
	return

def main():
	t = int(input())
	for i in range(t):
		solve()
	return
main()


for _ in range(int(input())):
	v = []
	(n, m) = map(int, input().split())
	for i in range(n):
		v.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != v[i][j] % 2:
				v[i][j] += 1
	for i in range(len(v)):
		print(*v[i])


t = int(input())
while t:
	(r, c) = map(int, input().split())
	mat = []
	for i in range(r):
		mat.append(list(map(int, input().split())))
	x = 0
	for i in range(r):
		f = x
		for j in range(c):
			if mat[i][j] % 2 == f:
				mat[i][j] += 1
			f = 1 if f == 0 else 0
		x = 1 if x == 0 else 0
	for i in range(r):
		for j in range(c):
			print(mat[i][j], end=' ')
		print()
	t -= 1


def solve():
	(n, m) = map(int, input().split())
	lst = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j + lst[i][j]) % 2:
				lst[i][j] += 1
	for i in lst:
		print(*i)
for i in range(int(input())):
	solve()


def solve(a):
	for i in range(len(a)):
		for j in range(len(a[i])):
			if (i + j) % 2 == 0 and a[i][j] % 2 != 0:
				a[i][j] += 1
			elif (i + j) % 2 != 0 and a[i][j] % 2 == 0:
				a[i][j] += 1
	for row in a:
		for item in row:
			print(item, end=' ')
		print()
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	a = [list(map(int, input().split())) for _ in range(n)]
	solve(a)


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [list(map(int, input().split())) for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0 and a[i][j] % 2 == 1:
				a[i][j] += 1
			elif (i + j) % 2 == 1 and a[i][j] % 2 == 0:
				a[i][j] += 1
	for ai in a:
		print(*ai)


from collections import Counter
from collections import OrderedDict
from collections import defaultdict
import bisect
import math
from sys import setrecursionlimit

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

def fre_count(mylist):
	return Counter(mylist)
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	grid = [[int(x) for x in input().split()] for x in range(n)]
	par = True
	for i in range(n):
		if i % 2 == 0:
			par = True
		else:
			par = False
		for j in range(m):
			if par:
				if grid[i][j] % 2 != 0:
					grid[i][j] += 1
			elif grid[i][j] % 2 == 0:
				grid[i][j] += 1
			par = not par
	for i in range(n):
		print(*grid[i])


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	a = []
	for i in range(n):
		a.append([int(i) for i in input().split()])
	for i in range(n):
		for j in range(m):
			if a[i][j] % 2 != (i + j) % 2:
				a[i][j] += 1
	for i in a:
		print(*i)


import sys
from collections import deque
from copy import *
from bisect import *
from math import gcd, ceil, sqrt
from itertools import permutations as prm, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def gtc(tc, ans):
	print('Case #' + str(tc) + ':', ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	(n, m) = mi()
	a = []
	for i in range(n):
		a.append(li())
	for i in range(n):
		for j in range(m):
			if i + j & 1:
				a[i][j] = a[i][j] if a[i][j] % 2 else a[i][j] + 1
			else:
				a[i][j] = a[i][j] + 1 if a[i][j] % 2 else a[i][j]
	for i in a:
		print(*i)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		s = list(map(int, input().split()))
		l.append(s)
	flag = 0
	if m % 2 == 0:
		for i in range(n):
			for j in range(m):
				if flag == 0:
					if l[i][j] % 2 == 1:
						print(l[i][j] + 1, end=' ')
					else:
						print(l[i][j], end=' ')
					flag = 1
				else:
					if l[i][j] % 2 == 0:
						print(l[i][j] + 1, end=' ')
					else:
						print(l[i][j], end=' ')
					flag = 0
			if flag == 1:
				flag = 0
			else:
				flag = 1
			print('')
	else:
		for i in range(n):
			for j in range(m):
				if flag == 0:
					if l[i][j] % 2 == 1:
						print(l[i][j] + 1, end=' ')
					else:
						print(l[i][j], end=' ')
					flag = 1
				else:
					if l[i][j] % 2 == 0:
						print(l[i][j] + 1, end=' ')
					else:
						print(l[i][j], end=' ')
					flag = 0
			print('')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
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
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7

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

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

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

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())):
	(n, m) = sp()
	mat = [l() for __ in range(n)]
	for i in range(n):
		for j in range(m):
			if i + j & 1:
				if mat[i][j] & 1:
					mat[i][j] += 1
			elif not mat[i][j] & 1:
				mat[i][j] += 1
	for i in mat:
		outa(*i)


def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))
t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	arr = []
	for _ in range(n):
		arr.append([int(x) for x in input().split()])
	for i in range(n):
		for j in range(m):
			desiredEvenParity = True if (i + j) % 2 == 0 else False
			if (arr[i][j] % 2 == 0) != desiredEvenParity:
				arr[i][j] += 1
	multiLineArrayOfArraysPrint(arr)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	grid = [[] for j in range(n)]
	for i in range(n):
		row = [int(i) for i in input().split() if i != '\n']
		for j in row:
			grid[i].append(j)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				if grid[i][j] % 2 != 0:
					grid[i][j] += 1
			elif grid[i][j] % 2 != 1:
				grid[i][j] += 1
	for i in range(len(grid)):
		print(*grid[i])


ansl = []
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	for i in range(n):
		row = list(map(int, input().split()))
		for j in range(m):
			if (i + j) % 2 == 0 and row[j] % 2 == 0:
				row[j] += 1
			elif (i + j) % 2 == 1 and row[j] % 2 == 1:
				row[j] += 1
		ansl.append(row)
for row in ansl:
	print(*row)


def solve():
	input_str = input().split()
	(m, n) = (int(input_str[0]), int(input_str[1]))
	nums = []
	for i in range(m):
		nums.append(list(map(int, input().split())))
	for i in range(m):
		for j in range(n):
			if i + j & 1 == 0:
				if nums[i][j] & 1 == 0:
					nums[i][j] += 1
			elif nums[i][j] & 1:
				nums[i][j] += 1
	for i in range(m):
		for j in range(n):
			print(nums[i][j], end=' ')
		print()
	return 0
t = int(input())
while t:
	solve()
	t -= 1


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		c = list(map(int, input().split()))
		arr.append(c)
	for i in range(n):
		for g in range(m):
			if i % 2 ^ g % 2 != arr[i][g] % 2:
				arr[i][g] += 1
	for i in range(n):
		print(*arr[i])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	plan = [[int(i) for i in input().split()] for j in range(n)]
	for i in range(n):
		for j in range(m):
			plan[i][j] += (i % 2 + j % 2 + plan[i][j] % 2) % 2
	for i in range(n):
		print(*plan[i])


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	res = []
	for i in range(n):
		l = list(map(int, input().split()))
		for j in range(m):
			if i & 1 and j & 1 or (i & 1 == 0 and j & 1 == 0):
				if l[j] & 1:
					l[j] += 1
			elif l[j] & 1 == 0:
				l[j] += 1
		res.append(l)
	for i in res:
		print(*i)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, m) = inp()
	arr = []
	for i in range(n):
		ch = list(inp())
		arr.append(ch)
	xor = 0
	for i in range(n):
		if xor == 0:
			for j in range(m):
				if j % 2 == 0:
					if arr[i][j] % 2 != 0:
						arr[i][j] += 1
				elif arr[i][j] % 2 == 0:
					arr[i][j] += 1
		else:
			for j in range(m):
				if j % 2 == 1:
					if arr[i][j] % 2 != 0:
						arr[i][j] += 1
				elif arr[i][j] % 2 == 0:
					arr[i][j] += 1
		xor ^= 1
	for i in arr:
		print(*i)


import sys
input = sys.stdin.readline
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]

def check(x, y, n, m):
	if x < 0 or y < 0 or x >= n or (y >= m):
		return False
	return True

def dfs(x, y, n, m, suggest):
	ar[x][y] += suggest
	for i in range(4):
		if check(x + dx[i], y + dy[i], n, m):
			if v[x + dx[i]][y + dy[i]] + ar[x + dx[i]][y + dy[i]] == v[x][y] + ar[x][y]:
				if ar[x + dx[i]][y + dy[i]] == 1:
					dfs(x + dx[i], y + dy[i], n, m, -1)
				elif ar[x + dx[i]][y + dy[i]] == 0:
					dfs(x + dx[i], y + dy[i], n, m, 1)
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	ar = [[0 for i in range(m)] for j in range(n)]
	v = []
	for j in range(n):
		v.append([int(i) for i in input().split() if i != '\n'])
	for i in range(n):
		for j in range(m):
			dfs(i, j, n, m, 0)
	for i in range(n):
		for j in range(m):
			v[i][j] += ar[i][j]
	for i in range(n):
		out = ' '.join(map(str, v[i]))
		sys.stdout.write(out + '\n')


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		l = list(map(int, input().split()))
		a.append(l)
	f1 = 0
	for i in range(n):
		f = f1
		for j in range(m):
			if a[i][j] % 2 == f:
				pass
			else:
				a[i][j] += 1
			if f == 0:
				f = 1
			else:
				f = 0
		if f1 == 0:
			f1 = 1
		else:
			f1 = 0
	for i in range(n):
		for j in range(m):
			print(a[i][j])
		print()


for __ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	ar = []
	for i in range(n):
		ar.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != ar[i][j] % 2:
				ar[i][j] += 1
	for elem in ar:
		print(*elem)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	c = []
	for i in range(n):
		l = list(map(int, input().split()))
		a.append(l)
		c.append([0] * m)
	j = 0
	for i in range(n):
		for k in range(m):
			if i == 0 and k == 0:
				continue
			elif k == 0 and i != 0:
				if a[i - 1][k] % 2 == a[i][k] % 2:
					a[i][k] += 1
			elif a[i][k] % 2 == a[i][k - 1] % 2:
				a[i][k] += 1
	for i in range(n):
		for k in range(m):
			print(a[i][k], end=' ')
		print()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat += [[int(j) for j in input().split()]]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				if mat[i][j] % 2 == 1:
					mat[i][j] += 1
			elif mat[i][j] % 2 == 0:
				mat[i][j] += 1
	for x in mat:
		print(*x)


(n, m) = (0, 0)
arr = []

def in_array(i, j):
	return 0 <= i < n and 0 <= j < m

def process():
	q = 0
	for k in range(n + m):
		i = k
		j = 0
		q = 1 - q
		for r in range(k + 1):
			if in_array(i, j):
				if arr[i][j] % 2 == q:
					arr[i][j] += 1
			i -= 1
			j += 1

def print_arr():
	for i in range(n):
		print(*arr[i])
t = int(input())
for g in range(t):
	(n, m) = map(int, input().split())
	arr.clear()
	for i in range(n):
		arr.append([int(e) for e in input().split()])
	process()
	print_arr()


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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:
			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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

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

def listStr():
	return list(input())

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

def isInt(s):
	return '0' <= s[0] <= '9'

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

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

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for _ in range(num):
	(n, m) = zzz()
	for i in range(n):
		arr = zzz()
		for j in range(m):
			arr[j] += (i + j) % 2 != arr[j] % 2
		print(*arr)


import sys
from math import ceil, factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
MOD = 10 ** 9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(int(input())):
	(n, m) = rl()
	nums = [rl() for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if (nums[i][j] - i - j) % 2:
				nums[i][j] += 1
		print(*nums[i])


import sys

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

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

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

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x))

def get_print(x):
	sys.stdout.write(str(x))

def solve():
	for _ in range(get_int()):
		(n, m) = get_ints()
		mat = []
		for i in range(n):
			mat.append(get_list())
		for i in range(n):
			for j in range(m):
				mat[i][j] += (i + j) % 2 != mat[i][j] % 2
		for i in mat:
			get_print(' '.join(map(str, i)))
			get_print('\n')
solve()


t = int(input())
a = [[0] * 100] * 100
for tt in range(t):
	(n, m) = list(map(int, input().split(' ')))
	for i in range(n):
		a[i] = list(map(int, input().split(' ')))
	for i in range(n):
		for j in range(m):
			a[i][j] += (a[i][j] + i + j) % 2
	for i in range(n):
		for j in range(m):
			print(a[i][j], end=' ')
		print()


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	mat = [0 for x in range(n)]
	for i in range(n):
		mat[i] = [int(x) for x in input().split()]
	p = 0
	for i in range(n):
		for j in range(m):
			if mat[i][j] % 2 != p % 2:
				mat[i][j] += 1
			p += 1
		if m % 2 == 0:
			p += 1
	for i in range(n):
		for j in range(m):
			stdout.write(str(mat[i][j]) + ' ')
		stdout.write('\n')


from math import *
from sys import *
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = []
	for i in range(n):
		m = list(map(int, stdin.readline().split()))
		a.append(m)
	f = 0
	for i in range(n):
		for j in range(k):
			if f == 0:
				if j % 2 == 0:
					if a[i][j] % 2 == 1:
						a[i][j] += 1
				elif a[i][j] % 2 == 0:
					a[i][j] += 1
			elif j % 2 == 0:
				if a[i][j] % 2 == 0:
					a[i][j] += 1
			elif a[i][j] % 2 == 1:
				a[i][j] += 1
		f += 1
		f = f % 2
	for i in range(n):
		print(*a[i])


import sys
input = sys.stdin.buffer.readline
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().decode().rstrip('\n\r')
wrt = sys.stdout.write
pr = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
xrange = lambda args: reversed(range(args))
cdiv = lambda x, y: -(-x // y)
enum = enumerate
inf = float('inf')
mod = 10 ** 9 + 7
from collections import defaultdict as dd
Cases = ri()
for Case in range(Cases):
	(n, m) = rl()
	g = []
	for i in range(n):
		g.append(rl())
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0 and g[i][j] % 2 == 1:
				g[i][j] += 1
			if (i + j) % 2 == 1 and g[i][j] % 2 == 0:
				g[i][j] += 1
	for i in range(n):
		print(*g[i])


t = int(input())
i = 0
while i < t:
	(n, m) = map(int, input().split())
	index = 0
	B = []
	while index < n:
		b = list(map(int, input().split()))
		B.append(b)
		index += 1
	I = 0
	answer = ''
	while I < n:
		J = 0
		while J < m:
			if (I + J) % 2 == 0:
				if B[I][J] % 2 == 1:
					B[I][J] += 1
				answer += str(B[I][J]) + ' '
			else:
				if B[I][J] % 2 == 0:
					B[I][J] += 1
				answer += str(B[I][J]) + ' '
			J += 1
		if I != n - 1:
			answer += '\n'
		I += 1
	print(answer)
	i += 1


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from collections import defaultdict
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

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

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

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

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 + 7

def solve():
	(n, m) = IP()
	li = []
	for i in range(n):
		temp = L()
		li.append(temp)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 and li[i][j] % 2 == 0:
				li[i][j] += 1
			elif (i + j) % 2 == 0 and li[i][j] % 2 == 1:
				li[i][j] += 1
	for ele in li:
		print(*ele)
t = II()
for i in range(t):
	solve()


t = int(input())
i = 1
while i <= t:
	[n, m] = list(map(int, input().split()))
	mat = []
	for j in range(n):
		mat.append(list(map(int, input().split())))
	for j in range(n):
		for k in range(m):
			if j % 2 == 0 and k % 2 == 0 or (j % 2 != 0 and k % 2 != 0):
				if mat[j][k] % 2 != 0:
					mat[j][k] += 1
			elif mat[j][k] % 2 == 0:
				mat[j][k] += 1
	for j in range(n):
		for k in range(m):
			print(mat[j][k], end=' ')
		print()
	print()
	i += 1


from sys import stdin, stdout
mp = lambda : map(int, stdin.readline().split())
li = lambda : list(map(int, stdin.readline().split()))
for _ in range(int(input())):
	(n, m) = mp()
	l = []
	for i in range(n):
		l.append(li())
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				if l[i][j] % 2 != 0:
					l[i][j] += 1
			elif l[i][j] % 2 == 0:
				l[i][j] += 1
	for i in range(n):
		for j in range(m):
			print(l[i][j], end=' ')
		print()


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	a = []
	[a.append(list(map(int, input().split()))) for i in range(r)]
	for i in range(r):
		for j in range(c):
			if not (i + j) % 2 and a[i][j] % 2:
				a[i][j] += 1
			elif (i + j) % 2 and (not a[i][j] % 2):
				a[i][j] += 1
	for i in a:
		print(*i)


import sys
input = sys.stdin.readline

def main():
	(n, m) = map(int, input().split())
	alst = [list(map(int, input().split())) for _ in range(n)]
	blst = [[0 for _ in range(m)] for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == alst[i][j] % 2:
				blst[i][j] = alst[i][j]
			else:
				blst[i][j] = alst[i][j] + 1
	for row in blst:
		print(*row)
for _ in range(int(input())):
	main()


cases = int(input())
for t in range(cases):
	(n, m) = list(map(int, input().split()))
	for i in range(n):
		row = list(map(int, input().split()))
		if i % 2 == 0:
			for j in range(m):
				if j % 2 == 0:
					row[j] = row[j] if row[j] % 2 == 0 else row[j] + 1
				else:
					row[j] = row[j] if row[j] % 2 == 1 else row[j] + 1
		else:
			for j in range(m):
				if j % 2 == 1:
					row[j] = row[j] if row[j] % 2 == 0 else row[j] + 1
				else:
					row[j] = row[j] if row[j] % 2 == 1 else row[j] + 1
		print(*row)


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

def gift():
	for _ in range(t):
		(n, m) = list(map(int, input().split()))
		ans = []
		for i in range(n):
			ans.append(list(map(int, input().split())))
		for i in range(n):
			for j in range(m):
				if ans[i][j] & 1 == i + j & 1:
					ans[i][j] += 1
		for i in range(n):
			yield ' '.join([str(x) for x in ans[i]])
t = int(input())
ans = gift()
print(*ans, sep='\n')


p = lambda : list(map(int, input().split()))
for _ in range(p()[0]):
	(n, m) = p()
	[print(*(a + (a + i + j) % 2 for (j, a) in enumerate(p()))) for i in range(n)]


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	for i in range(n):
		mas = [int(s) for s in input().split()]
		for j in range(m):
			if i % 2 == j % 2 and mas[j] % 2 == 0:
				mas[j] += 1
			elif i % 2 != j % 2 and mas[j] % 2 == 1:
				mas[j] += 1
		print(' '.join(map(str, mas)))


from heapq import heappush, heappop
from math import inf
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')
T = int(input())
for _ in range(T):
	(r, c) = map(int, input().split())
	arr = []
	for _ in range(r):
		arr.append(list(map(int, input().split())))
	for i in range(r):
		for j in range(c):
			arr[i][j] += (arr[i][j] + i + j) % 2
		print(*arr[i])


t = int(input())

def make(n, m, L):
	G = [[y for y in x] for x in L]
	for i in range(n):
		for j in range(m):
			x = L[i][j]
			if (i + j) % 2 == 0 and x % 2 == 1:
				G[i][j] += 1
			if (i + j) % 2 == 1 and x % 2 == 0:
				G[i][j] += 1
	return G
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	L = []
	for i in range(n):
		L.append([int(x) for x in input().split()])
	G = make(n, m, L)
	for x in G:
		print(*x)


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from itertools import *

def main():
	(n, m) = iia()
	arr = []
	for i in range(n):
		arr.append(iia())
	dp = [[[0, 0]] * m for i in range(n)]
	for i in range(n):
		for j in range(m):
			if arr[i][j] % 2 == (i + j) % 2:
				arr[i][j] += 1
	[print(*arr[i]) for i in range(n)]
for i in range(ii1()):
	main()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	grid = []
	for _ in range(n):
		row = list(map(int, input().split()))
		grid.append(row)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0 and grid[i][j] % 2 != 0 or ((i + j) % 2 == 1 and grid[i][j] % 2 != 1):
				grid[i][j] += 1
			print(grid[i][j], end=' ')
		print()


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = [[0 for k in range(m)] for j in range(n)]
	ans = [[0 for k in range(m)] for j in range(n)]
	for l in range(n):
		v = list(map(int, input().split()))
		for u in range(m):
			a[l][u] = v[u]
	for y in range(n):
		for p in range(m):
			if (p + y) % 2 == 0 and a[y][p] % 2 != 0:
				ans[y][p] = a[y][p] + 1
			elif (p + y) % 2 != 0 and a[y][p] % 2 == 0:
				ans[y][p] = a[y][p] + 1
			else:
				ans[y][p] = a[y][p]
	for h in range(n):
		print(*ans[h], sep=' ')


for _ in range(int(input())):
	(N, M) = [int(i) for i in input().split(' ')]
	matrix = []
	for i in range(N):
		matrix.append([int(i) for i in input().split(' ')])
	for i in range(N):
		for j in range(M):
			if (i + j) % 2 == 0:
				if matrix[i][j] % 2 != 0:
					matrix[i][j] += 1
			elif matrix[i][j] % 2 == 0:
				matrix[i][j] += 1
	for i in range(N):
		for j in range(M):
			print(matrix[i][j], end=' ')
		print()


t = int(input())
for p in range(t):
	(n, m) = map(int, input().split(' '))
	lst = []
	for q in range(n):
		lst.append(list(map(int, input().split(' '))))
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				lst[i][j] += lst[i][j] % 2
			else:
				lst[i][j] += 0 if lst[i][j] % 2 else 1
	print('\n'.join((' '.join(map(str, i)) for i in lst)))


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	l = []
	for i in range(r):
		l.append(list(map(int, input().split())))
	odd = True
	for i in range(r):
		for j in range(c):
			cur = l[i][j]
			if odd:
				if j % 2 == 0:
					if cur % 2 != 0:
						l[i][j] = cur + 1
				elif cur % 2 == 0:
					l[i][j] = cur + 1
			elif j % 2 == 0:
				if cur % 2 == 0:
					l[i][j] = cur + 1
			elif cur % 2 != 0:
				l[i][j] = cur + 1
		odd = not odd
	for i in l:
		print(*i)


for I in range(int(input())):
	(n, m) = map(int, input().split())
	for i in range(n):
		a = list(map(int, input().split()))
		if i % 2 == 0:
			for j in range(m):
				if j % 2 == 0:
					if a[j] % 2 == 1:
						a[j] += 1
				elif a[j] % 2 == 0:
					a[j] += 1
		else:
			for j in range(m):
				if j % 2 == 1:
					if a[j] % 2 == 1:
						a[j] += 1
				elif a[j] % 2 == 0:
					a[j] += 1
		print(*a)


def solve(n, m):
	a = []
	for i in range(n):
		l = list(map(int, input().split()))
		a.append(l)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				if a[i][j] % 2 != 0:
					a[i][j] += 1
			elif a[i][j] % 2 == 0:
				a[i][j] += 1
	for i in a:
		print(*i)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	solve(n, m)


a = int(input())
for i in range(a):
	(n, m) = [int(_) for _ in input('').split()]
	for j in range(n):
		arr = [int(_) for _ in input('').split()]
		for k in range(m):
			if (j + k) % 2 == 0:
				if arr[k] % 2 != 0:
					print(arr[k] + 1, end=' ')
				else:
					print(arr[k], end=' ')
			elif arr[k] % 2 == 0:
				print(arr[k] + 1, end=' ')
			else:
				print(arr[k], end=' ')
		print()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		lst = list(map(int, input().split()))
		mat.append(lst)
		for j in range(0, m):
			if (i + j) % 2 == lst[j] % 2:
				lst[j] += 1
			else:
				continue
	for i in range(n):
		print(*mat[i])


from sys import stdin, stdout
from math import factorial as f
from random import randint, shuffle
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [[*map(int, input().split())] for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if i + j & 1 ^ a[i][j] & 1:
				a[i][j] += 1
	for i in a:
		print(*i)


from sys import stdin

def si():
	return stdin.readline().strip()

def ii():
	return int(si())

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

def li():
	return list(mi())
t = ii()
for _ in range(t):
	(n, m) = mi()
	a = [li() for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (a[i][j] - i - j) % 2 != 0:
				a[i][j] += 1
		print(*a[i])


a = [[0] * 110] * 110
tc = eval(input())
while tc:
	tc -= 1
	(n, m) = map(int, input().split())
	for i in range(n):
		a[i] = [int(j) for j in input().split()]
		for j in range(m):
			if i + j & 1 != a[i][j] & 1:
				a[i][j] += 1
			print(a[i][j], end=' \n'[j == m - 1])


t = int(input())
for case in range(t):
	(n, m) = [int(x) for x in input().split(' ')]
	a = [[int(x) for x in input().split(' ')] for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (a[i][j] - (i + j)) % 2 != 0:
				a[i][j] += 1
	for row in a:
		print(*row)


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
from random import *
import sys
input = sys.stdin.readline

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

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

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	(n, m) = ma()
	r = []
	for i in range(n):
		a = lis()
		r.append(a)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2:
				r[i][j] += r[i][j] % 2
			else:
				r[i][j] += r[i][j] % 2 ^ 1
	for i in r:
		print(*i)


t = int(input())
for p in range(t):
	(n, m) = map(int, input().split())
	arr = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0 and arr[i][j] % 2 != 0 or ((i + j) % 2 != 0 and arr[i][j] % 2 == 0):
				arr[i][j] += 1
		print(*arr[i])


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(qw) for qw in ii().split()]

def solve():
	(n, m) = idata()
	for i in range(n):
		data = idata()
		if i % 2:
			for j in range(m):
				if j % 2:
					data[j] = (data[j] + 1) // 2 * 2
				else:
					data[j] = data[j] // 2 * 2 + 1
		else:
			for j in range(m):
				if j % 2 == 0:
					data[j] = (data[j] + 1) // 2 * 2
				else:
					data[j] = data[j] // 2 * 2 + 1
		print(*data)
	return
for _t in range(int(ii())):
	solve()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for __ in range(n):
		grid.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(m):
			if grid[i][j] % 2 == (i + j) % 2:
				grid[i][j] += 1
		print(*grid[i])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [[int(i) for i in input().split()] for j in range(n)]
	for k in range(n):
		for l in range(m):
			if k % 2 == 0 and l % 2 == 0:
				if arr[k][l] % 2 == 0:
					pass
				else:
					arr[k][l] += 1
			if k % 2 != 0 and l % 2 == 0:
				if arr[k][l] % 2 != 0:
					pass
				else:
					arr[k][l] += 1
			if k % 2 == 0 and l % 2 != 0:
				if arr[k][l] % 2 != 0:
					pass
				else:
					arr[k][l] += 1
			if k % 2 != 0 and l % 2 != 0:
				if arr[k][l] % 2 == 0:
					pass
				else:
					arr[k][l] += 1
	for i in range(n):
		print(*arr[i])


for _ in range(int(input())):
	(n, m) = [int(c) for c in input().split()]
	arr = [[0 for i in range(m + 1)]]
	for i in range(n):
		ar = [int(c) for c in input().split()]
		arr.append([0] + ar)
	for i in range(n + 1):
		for j in range(m + 1):
			if i + j & 1 != arr[i][j] & 1:
				arr[i][j] += 1
	for i in range(1, n + 1):
		print(*arr[i][1:])


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	a = [[int(x) for x in input().split()] for i in range(n)]
	for i in range(n):
		for j in range(m):
			d = a[i][j] % 2 == 0
			e = i % 2 == j % 2
			if d != e:
				a[i][j] += 1
	for i in a:
		print(*i)


def main():
	t = int(input())
	for i_t in range(t):
		(n, m) = _read_ints()
		a = tuple((tuple(_read_ints()) for i_row in range(n)))
		result = _find_fixed_matrix(a)
		for row in result:
			print(*row)

def _find_fixed_matrix(matrix):
	rows_n = len(matrix)
	columns_n = len(matrix[0])
	elements_n = rows_n * columns_n
	result = tuple(map(list, matrix))
	actions = tuple(([None] * columns_n for i_row in range(rows_n)))
	queue = []
	i_action = 0
	for i_row in range(rows_n):
		for i_column in range(columns_n):
			if actions[i_row][i_column] is None:
				actions[i_row][i_column] = 1
				queue.append(((i_row, i_column), 1))
				while i_action != len(queue):
					((u, v), action) = queue[i_action]
					i_action += 1
					for (du, dv) in ((0, 1), (1, 0), (0, -1), (-1, 0)):
						if 0 <= u + du < rows_n and 0 <= v + dv < columns_n and (actions[u + du][v + dv] is None):
							try:
								action = _try_choose_action((u + du, v + dv), matrix, actions)
							except ValueError:
								pass
							else:
								actions[u + du][v + dv] = action
								queue.append(((u + du, v + dv), action))
			result[i_row][i_column] += actions[i_row][i_column]
	return result

def _try_choose_action(pos, matrix, actions):
	rows_n = len(matrix)
	columns_n = len(matrix[0])
	(u, v) = pos
	for (du, dv) in ((0, 1), (1, 0), (0, -1), (-1, 0)):
		if 0 <= u + du < rows_n and 0 <= v + dv < columns_n and (actions[u + du][v + dv] is not None):
			new_value = matrix[u + du][v + dv] + actions[u + du][v + dv]
			if matrix[u][v] == new_value:
				return 1
			elif matrix[u][v] + 1 == new_value:
				return 0
	raise ValueError

def _read_ints():
	return map(int, input().split())
main()


import sys
t = int(input())
for test in range(t):
	[n, m] = list(map(int, input().split(' ')))
	a = []
	for i in range(n):
		a.append(list(map(int, input().split(' '))))
	for i in range(n):
		for j in range(m):
			if a[i][j] % 2 != (i + j) % 2:
				a[i][j] += 1
		b = [str(x) for x in a[i]]
		print(' '.join(b))


def solve(arr):
	flag = True
	for i in range(n):
		for j in range(m):
			if flag:
				if j % 2 == 0 and arr[i][j] % 2 != 0:
					arr[i][j] += 1
				elif j % 2 != 0 and arr[i][j] % 2 == 0:
					arr[i][j] += 1
			elif j % 2 == 0 and arr[i][j] % 2 == 0:
				arr[i][j] += 1
			elif j % 2 != 0 and arr[i][j] % 2 != 0:
				arr[i][j] += 1
		flag = not flag
	return arr
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = [[-1 for i in range(m)] for j in range(n)]
	for i in range(n):
		s = [int(k) for k in input().split()]
		for j in range(m):
			arr[i][j] = int(s[j])
	ans = solve(arr)
	for i in ans:
		print(*i)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	for k in range(n):
		L = list(map(int, input().split()))
		for i in range(m):
			if i % 2 == 0 and k % 2 == 0:
				print(L[i] + 1 - L[i] % 2, end=' ')
			elif i % 2 == 1 and k % 2 == 1:
				print(L[i] + 1 - L[i] % 2, end=' ')
			else:
				print(L[i] + L[i] % 2, end=' ')
		k = k + 1
		print()


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	A = []
	for i in range(n):
		A.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(m):
			if A[i][j] % 2 != (i + j) % 2:
				A[i][j] = A[i][j] + 1
	for i in range(n):
		print(*A[i])


import itertools
import math
import sys
import os
from collections import defaultdict

def is_debug():
	return 'PYPY3_HOME' not in os.environ

def stdin_wrapper():
	data = '3\n3 2\n1 2\n4 5\n7 8\n2 2\n1 1\n3 3\n2 2\n1 3\n2 2\n'
	for line in data.split('\n'):
		yield line
if not is_debug():

	def stdin_wrapper():
		while True:
			yield sys.stdin.readline()
inputs = stdin_wrapper()

def input_wrapper():
	return next(inputs)

def get_str():
	if is_debug():
		return input_wrapper()
	return input()

def get(_type):
	if _type == str:
		return get_str()
	return _type(input_wrapper())

def get_arr(_type):
	return [_type(x) for x in input_wrapper().split()]

def tuplerize(method):

	def wrap(*args, **kwargs):
		res = method(*args, **kwargs)
		if not isinstance(res, (tuple, list)):
			res = (res,)
		return res
	return wrap

@tuplerize
def solve(n, m, mx):
	for y in range(n):
		for x in range(m):
			if (x + y) % 2 and mx[y][x] % 2 == 0:
				mx[y][x] += 1
			elif (x + y) % 2 == 0 and mx[y][x] % 2:
				mx[y][x] += 1
	return '\n'.join([' '.join(map(str, row)) for row in mx])
t = get(int)
for _ in range(t):
	(n, m) = get_arr(int)
	mx = [None] * n
	for i in range(n):
		mx[i] = get_arr(int)
	print(*solve(n, m, mx))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 32, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=2 ** 30 - 1, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != a[i][j] % 2:
				a[i][j] += 1
	for i in range(n):
		print(*a[i])


def f(a, n, m):
	for i in range(n):
		for j in range(m):
			if (a[i][j] ^ i ^ j) & 1:
				a[i][j] += 1
	return a
for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	a = f(a, n, m)
	for i in a:
		print(*i, sep=' ')


tc = int(input())
for i in range(tc):
	(n, m) = map(int, input().split())
	arr = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (arr[i][j] - i - j) % 2 != 0:
				arr[i][j] += 1
		print(*arr[i])


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import defaultdict as dd
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdmap = lambda : map(int, stdstr().split())
stdarr = lambda : list(map(int, stdstr().split()))
mod = 1000000007
for _ in range(stdint()):
	(n, m) = stdmap()
	matrix = []
	for i in range(n):
		row = stdarr()
		matrix.append(row)
	eo = [[None for __ in range(m)] for ___ in range(n)]
	change = [[0 for __ in range(m)] for ___ in range(n)]
	for i in range(n):
		for j in range(m):
			if matrix[i][j] % 2 == 0:
				eo[i][j] = 0
			else:
				eo[i][j] = 1
	f = eo[0][0]
	lastR = f
	last = f
	suitable = [[None for __ in range(m)] for ___ in range(n)]
	for i in range(n):
		if i != 0:
			lastR ^= 1
			last = lastR
		for j in range(m):
			if i == 0 and j == 0:
				suitable[i][j] = f
			elif j == 0:
				suitable[i][j] = lastR
			else:
				last ^= 1
				suitable[i][j] = last
	for i in range(n):
		for j in range(m):
			if suitable[i][j] != eo[i][j]:
				matrix[i][j] += 1
	for i in range(n):
		print(*matrix[i])


import sys
import math
input = sys.stdin.readline
t = int(input())
for w in range(t):
	(n, m) = (int(i) for i in input().split())
	l = []
	for i in range(n):
		l.append([int(i) for i in input().split()])
	for i in range(n):
		if i % 2 == 0:
			for j in range(m):
				if j % 2 == 0:
					if l[i][j] % 2 != 0:
						l[i][j] += 1
				elif l[i][j] % 2 == 0:
					l[i][j] += 1
		else:
			for j in range(m):
				if j % 2 == 0:
					if l[i][j] % 2 == 0:
						l[i][j] += 1
				elif l[i][j] % 2 != 0:
					l[i][j] += 1
	for i in range(n):
		print(*l[i])


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		b = list(map(int, input().split()))
		a.append(b)
	for i in range(n):
		if i % 2 == 0:
			for j in range(m):
				if j % 2 == 0:
					if a[i][j] % 2 == 1:
						a[i][j] += 1
				elif a[i][j] % 2 == 0:
					a[i][j] += 1
		else:
			for j in range(m):
				if j % 2 == 0:
					if a[i][j] % 2 == 0:
						a[i][j] += 1
				elif a[i][j] % 2 == 1:
					a[i][j] += 1
	for i in range(n):
		for j in range(m):
			print(a[i][j], end=' ')
		print()


import sys
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	b = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == b[i][j] % 2:
				b[i][j] += 1
	for i in b:
		print(*i)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	tabl = [[int(i) for i in input().split()] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == tabl[i][j] % 2:
				tabl[i][j] += 1
		print(*tabl[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):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def solve(n, m, lst):
	for i in range(n):
		for j in range(m):
			if lst[i][j] % 2 != (i + j) % 2:
				lst[i][j] += 1
	for i in lst:
		for j in i:
			print(j, end=' ')
		print()
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	lst = []
	for i in range(n):
		lst.append(list(map(int, input().split())))
	solve(n, m, lst)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	for i in range(m):
		A = list(map(int, input().split()))
		for j in range(n):
			if A[j] % 2 != (i + j) % 2:
				print(A[j] + 1, end=' ')
			else:
				print(A[j], end=' ')
		print()


t = int(input())
ad = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def aze(x, y):
	if x < n and x > -1 and (y < m) and (y > -1):
		return True
	return False
print()

def dfs(k):
	q = [k]
	while q:
		x = q.pop()
		(i, j) = (x // m, x % m)
		for w in ad:
			(ip, jp) = (i + w[0], j + w[1])
			if not aze(ip, jp):
				continue
			if mat[i][j] != mat[ip][jp]:
				continue
			q.append(jp + ip * m)
			if vi[jp + ip * m]:
				mat[ip][jp] -= 1
				vi[jp + ip * m] = False
			else:
				mat[ip][jp] += 1
				vi[jp + ip * m] = True
for _ in range(t):
	(n, m) = map(int, input().split())
	mat = [[] for i in range(n)]
	vi = [False for i in range(n * m)]
	for o in range(n):
		mat[o] = list(map(int, input().split()))
	for i in range(n):
		for j in range(m):
			dfs(j + i * m)
	for i in range(n):
		print(*mat[i])
	print()


t = int(input())
for _ in range(t):
	a = []
	(n, m) = map(int, input().split())
	for i in range(n):
		ar = list(map(int, input().split()))
		for j in range(m):
			if i + j & 1 != ar[j] & 1:
				ar[j] += 1
		a.append(ar)
	for i in a:
		for j in i:
			print(j, end=' ')
		print('')


N = int(input())
for i in range(N):
	(n, m) = map(int, input().split())
	for j in range(n):
		a = list(map(int, input().split()))
		for k in range(m):
			(mod1, mod2) = ((j + k) % 2, a[k] % 2)
			if mod1 != mod2:
				a[k] += 1
		print(*a)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	res = []
	for i in range(n):
		l = list(map(int, input().split()))
		res.append(l)
	for i in range(n):
		for j in range(m):
			if res[i][j] % 2 == (i + j) % 2:
				print(res[i][j], end=' ')
			else:
				print(res[i][j] + 1, end=' ')
		print()


def ans(grid, n, m):
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != grid[i][j] % 2:
				grid[i][j] += 1
			print(grid[i][j], end=' ')
		print()
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		row = list(map(int, input().split()))
		grid.append(row)
	ans(grid, n, m)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split(' ')))
	a = []
	for _ in range(n):
		a.append(list(map(int, input().split(' '))))
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				a[i][j] += a[i][j] % 2
			else:
				a[i][j] += not a[i][j] % 2
	for i in range(n):
		print(*a[i])


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	l = []
	for i in range(n):
		l.append([int(x) for x in input().split()])
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != l[i][j] % 2:
				l[i][j] += 1
	for i in l:
		print(*i)


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())
y = inp()
for _ in range(y):
	[r, c] = inlt()
	m = []
	for i in range(r):
		m.append(inlt())
	b = m.copy()
	for i in range(r):
		for j in range(c):
			if (i + j) % 2 != m[i][j] % 2:
				m[i][j] += 1
	for i in range(r):
		ans = ''
		for j in range(c):
			ans += str(m[i][j]) + ' '
		print(ans)


import sys

def solve():
	(n, m) = map(int, input().strip().split())
	a = []
	for i in range(n):
		a.append(list(map(int, input().strip().split())))
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				a[i][j] += a[i][j] % 2
			else:
				a[i][j] += 1 - a[i][j] % 2
	for i in range(n):
		for j in range(m):
			sys.stdout.write(str(a[i][j]))
			sys.stdout.write(' ')
		sys.stdout.write('\n')
	return
T = int(input().strip())
for test_case in range(1, T + 1, 1):
	output = solve()


for ik in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	for i in range(n):
		for j in range(m):
			l[i][j] += abs(l[i][j] % 2 - (i + j) % 2)
	for i in range(n):
		print(*l[i])


p = lambda : list(map(int, input().split()))
for _ in range(p()[0]):
	(N, M) = p()
	a = [p() for _ in range(N)]
	for i in range(N):
		for j in range(M):
			if (i ^ j) & 1:
				a[i][j] += a[i][j] & 1
			if (~i ^ j) & 1:
				a[i][j] += ~a[i][j] & 1
	for r in a:
		print(*r)


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
YN = lambda x: print('YES') if x else print('NO')
pl = lambda l: print(' '.join(list(map(str, l))))
for _ in range(rn()):
	(n, m) = rns()
	mat = []
	for i in range(n):
		mat.append(rl())
	for i in range(n):
		for j in range(m):
			if i % 2 == j % 2:
				mat[i][j] += mat[i][j] % 2
			else:
				mat[i][j] += int(not mat[i][j] % 2)
	for i in mat:
		print(*i)


for _ in range(int(input())):
	r = [int(i) for i in input().split()]
	(n, p) = (r[0], r[1])
	m = []
	for i in range(n):
		u = [int(j) for j in input().split()]
		m.append(u)
	for i in range(len(m)):
		if i % 2 == 0:
			for j in range(len(m[i])):
				if j % 2 != 0 and m[i][j] % 2 != 0:
					m[i][j] += 1
				elif j % 2 == 0 and m[i][j] % 2 == 0:
					m[i][j] += 1
		else:
			for j in range(len(m[i])):
				if j % 2 == 0 and m[i][j] % 2 != 0:
					m[i][j] += 1
				elif j % 2 != 0 and m[i][j] % 2 == 0:
					m[i][j] += 1
	for i in range(len(m)):
		for j in range(len(m[i])):
			print(m[i][j], end=' ')
		print()


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
sys.setrecursionlimit(99999)
for _ in range(int(input())):
	(m, n) = map(int, input().split())
	for i in range(m):
		arr = list(map(int, input().split()))
		for j in range(n):
			if arr[j] - i - j & 1:
				arr[j] += 1
		print(*arr)


a = int(input())

def solved(arr, ii, jj):
	for i in range(ii, len(arr)):
		for j in range(jj, len(arr[0])):
			if i < len(arr) - 1 and arr[i][j] == arr[i + 1][j]:
				return False
			if j < len(arr[0]) - 1 and arr[i][j] == arr[i][j + 1]:
				return False
	return True

def solve(arr, i, j, fi, fj):
	arr[fi][fj] = arr[fi][fj] + 1
	if solved(arr, i, j):
		return True
	if j == len(arr[0]):
		i = i + 1
		j = 0
	if i == len(arr):
		arr[fi][fj] = arr[fi][fj] - 1
		return False
	for ii in range(i, len(arr)):
		for jj in range(j, len(arr[0])):
			if ii < len(arr) - 1 and arr[ii][jj] == arr[ii + 1][jj]:
				arr[ii][jj] == arr[ii][jj] + 1
				if solve(arr, ii, jj, ii, jj):
					return True
				else:
					solve(arr, ii, jj + 1, ii + 1, jj)
					return True
			if jj < len(arr[0]) - 1 and arr[ii][jj] == arr[ii][jj + 1]:
				arr[ii][jj] == arr[ii][jj] + 1
				if solve(arr, ii, jj, ii, jj):
					return True
				else:
					solve(arr, i, j + 1, i, j + 1)
					return True

def makeOdd(arr, i, j, count):
	if not arr[i][j] % 2 == count:
		arr[i][j] = arr[i][j] + 1

def flip(count):
	if count == 0:
		return 1
	else:
		return 0
for i in range(a):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(list(map(int, input().split())))
	count = 0
	for i in range(0, len(arr)):
		count = i % 2
		for j in range(0, len(arr[0])):
			makeOdd(arr, i, j, count)
			count = flip(count)
	for i in arr:
		print(' '.join(map(str, i)))


import math, sys
from collections import defaultdict, Counter, deque
from functools import reduce
INF = float('inf')
MOD = int(1000000000.0) + 7

def solve():
	(n, m) = vars()
	mat = []
	for i in range(n):
		mat.append(array())
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != mat[i][j] % 2:
				mat[i][j] += 1
	for row in mat:
		print(*row)

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

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

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

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(str(sep))
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)

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

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


T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	A = [list(map(int, input().split())) for i in range(N)]
	for i in range(N):
		for j in range(M):
			if (i + j) % 2:
				if A[i][j] % 2:
					A[i][j] += 1
			elif A[i][j] % 2 == 0:
				A[i][j] += 1
	for row in A:
		print(*row)


import sys, os
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve_(grid):
	res = []
	for (i, row) in enumerate(grid):
		cur = []
		for (j, cell) in enumerate(row):
			if (i + j) % 2 != cell % 2:
				grid[i][j] += 1
	return grid

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	pass
ONLINE_JUDGE = False
if os.path.exists('input.txt'):
	ONLINE_JUDGE = True
if ONLINE_JUDGE:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def console(*args):
		pass

def solve(*args):
	if not ONLINE_JUDGE:
		console('----- solving ------')
		console(*args)
		console('----- ------- ------')
	return solve_(*args)
if True:
	inp = iter(sys.stdin.buffer.readlines())
	input = lambda : next(inp)
else:
	input = sys.stdin.buffer.readline
for case_num in range(int(input())):
	(nrows, _) = list(map(int, input().split()))
	grid = []
	for _ in range(nrows):
		grid.append(list(map(int, input().split())))
	res = solve(grid)
	for r in res:
		print(*r)


import sys
import math
from sys import stdin, stdout

def sieve(N):
	primeNumbers = [True] * (N + 1)
	primeNumbers[0] = False
	primeNumbers[1] = False
	i = 2
	while i * i <= N:
		j = i
		if primeNumbers[j]:
			while j * i <= N:
				primeNumbers[j * i] = False
				j += 1
		i += 1
	return primeNumbers

def getPrime(N):
	primes = sieve(N)
	result = []
	for i in range(len(primes)):
		if primes[i]:
			result.append(i)
	return result

def factor(N):
	factors = []
	i = 1
	while i * i <= N:
		if N % i == 0:
			factors.append(i)
			if i != N // i:
				factors.append(N // i)
		i += 1
	return sorted(factors)

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

def extendedGcd(a, b):
	if a < b:
		return extendedGcd(b, a)
	if b == 0:
		return [a, 1, 0]
	res = extendedGcd(b, a % b)
	x = res[2]
	y = res[1] - math.floor(a / b) * res[2]
	res[1] = x
	res[2] = y
	return res

def iterativeModularFunc(a, b, c):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % c
		a = a * a % c
		b = b // 2
	return res

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

def get_int():
	return int(input())

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

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

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

def Solution(matrix, n, m):
	turn = 0
	for i in range(n):
		t = turn
		for j in range(m):
			if matrix[i][j] % 2 != t:
				matrix[i][j] += 1
			if t == 0:
				t = 1
			else:
				t = 0
		if turn == 0:
			turn = 1
		else:
			turn = 0
	for i in range(n):
		for j in range(m):
			print(matrix[i][j], end=' ')
		print()

def main():
	for _ in range(get_int()):
		(n, m) = get_ints_in_variables()
		matrix = get_list_of_list(n)
		Solution(matrix, n, m)
main()


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

def ti():
	return map(int, input().split(' '))

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

def tm(m):
	mat = []
	for i in range(m):
		mat.append(tl())
	return mat
for _ in range(int(input())):
	(n, m) = ti()
	mat = tm(n)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 and mat[i][j] % 2 == 0:
				mat[i][j] += 1
			elif (i + j) % 2 == 0 and mat[i][j] % 2:
				mat[i][j] += 1
	for i in range(n):
		print(*mat[i])


MOD = 1000000007
from collections import defaultdict as dd, Counter, deque

def si():
	return input()

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

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

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

def out(v):
	print(v)

def spout():
	print(v, end=' ')

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

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

def ispow2(x):
	return x and (not x & x - 1)

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)
t = ii()
while t:
	t -= 1
	(n, m) = mi()
	a = []
	for _ in range(n):
		a.append(li())
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0:
				if a[i][j] % 2 == 0:
					print(a[i][j], end=' ')
				else:
					print(a[i][j] + 1, end=' ')
			elif a[i][j] % 2 == 1:
				print(a[i][j], end=' ')
			else:
				print(a[i][j] + 1, end=' ')
		print()


for tetscase in range(int(input())):
	arr = [int(x) for x in input().split()]
	(n, m) = (arr[0], arr[1])
	arr = []
	for i in range(n):
		li = [int(x) for x in input().split()]
		if i % 2 == 0:
			for j in range(m):
				if j % 2 == 1 and li[j] % 2 == 1:
					li[j] += 1
				elif j % 2 == 0 and li[j] % 2 == 0:
					li[j] += 1
		else:
			for j in range(m):
				if j % 2 == 0 and li[j] % 2 == 1:
					li[j] += 1
				elif j % 2 == 1 and li[j] % 2 == 0:
					li[j] += 1
		arr.append(li)
	for ele in arr:
		print(*ele)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	f = []
	a = []
	for i in range(n):
		g = list(map(int, input().split()))
		if i % 2 == 0:
			for j in range(m):
				if j % 2 == 0:
					if g[j] % 2 == 0:
						pass
					else:
						g[j] += 1
				elif g[j] % 2 == 1:
					pass
				else:
					g[j] += 1
		else:
			for j in range(m):
				if j % 2 == 0:
					if g[j] % 2 == 1:
						pass
					else:
						g[j] += 1
				elif g[j] % 2 == 0:
					pass
				else:
					g[j] += 1
		f.append(g)
	for i in range(n):
		for j in range(m):
			print(f[i][j], end=' ')
		print()


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	arr = [[int(x) for x in input().split()] for i in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != arr[i][j] % 2:
				arr[i][j] += 1
	for row in arr:
		for i in row:
			print(i, end=' ')
		print()


for _ in range(0, int(input())):
	(n, m) = map(int, input().split())
	mat = [[] for _ in range(0, n)]
	elems = dict()
	srt = []
	mod = 0
	for i in range(0, n):
		mat[i] = [int(x) for x in input().split()]
		srt += mat[i]
		for j in range(0, m):
			if mat[i][j] not in elems:
				elems[mat[i][j]] = []
			elems[mat[i][j]].append((i, j))
	srt = list(set(srt))
	srt.sort()
	for elem in srt:
		mod ^= 1
		for (i, j) in elems[elem]:
			if (i + j) % 2 == mod:
				mat[i][j] += 1
	for i in range(0, n):
		for j in range(0, m):
			print(mat[i][j], end=' ')
		print()


try:
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		mat = [[int(i) for i in input().split()] for i in range(n)]
		for i in range(n):
			for j in range(m):
				if mat[i][j] % 2 != (i + j) % 2:
					mat[i][j] += 1
		for i in range(n):
			print(*mat[i])
except EOFError as e:
	print(e)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	table = [list(map(int, input().split())) for _ in range(m)]
	for i in range(m):
		for j in range(n):
			if (i + j) % 2 and table[i][j] % 2:
				table[i][j] += 1
			elif not (i + j) % 2 and (not table[i][j] % 2):
				table[i][j] += 1
	for t in table:
		print(*t)


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		(n, m) = mi()
		for i in range(n):
			for (j, x) in enumerate(li()):
				if i + j & 1 ^ x & 1:
					print(x + 1, end=' ')
				else:
					print(x, end=' ')
			print()
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


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 so():
	return int(input())

def st():
	return input()

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

def msj():
	return map(str, input().strip().split(' '))

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

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

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

def tr(n):
	return n * (n + 1) // 2

def main():
	import math
	for i in range(so()):
		(n, q) = mj()
		d = []
		for i in range(n):
			d.append(le())
		for i in range(n):
			for j in range(q):
				if d[i][j] % 2 != (i + j) % 2:
					d[i][j] = d[i][j] + 1
		for i in range(len(d)):
			print(*d[i])
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()


import sys
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	mat = [list(map(int, input().split())) for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if i % 2:
				if j % 2:
					mat[i][j] += 1 if mat[i][j] % 2 else 0
				else:
					mat[i][j] += 1 if mat[i][j] % 2 == 0 else 0
			elif j % 2:
				mat[i][j] += 1 if mat[i][j] % 2 == 0 else 0
			else:
				mat[i][j] += 1 if mat[i][j] % 2 else 0
	for each in mat:
		print(*each)
for _ in range(int(input())):
	solve()


def solve():
	(n, m) = list(map(int, input().split()))
	for i in range(n):
		a = list(map(int, input().split()))
		for j in range(m):
			if (i + j) % 2 == 0:
				if a[j] % 2 == 0:
					print(a[j], end=' ')
				else:
					print(a[j] + 1, end=' ')
			elif a[j] % 2 == 0:
				print(a[j] + 1, end=' ')
			else:
				print(a[j], end=' ')
		print()
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for brt in range(t):
	(n, m) = map(int, input().split())
	mat = n * [m * [0]]
	for i in range(n):
		mat[i] = list(map(int, input().split()))
		for j in range(m):
			if mat[i][j] % 2 != (i + j) % 2:
				mat[i][j] += 1
	for i in range(n):
		for j in range(m):
			print(mat[i][j], ' ', end='', sep='')
		print()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for j in range(n):
		l = list(map(int, input().split()))
		arr.append(l)
	f = 0
	for k in range(n):
		f1 = f
		for l in range(m):
			if arr[k][l] % 2 != f1:
				arr[k][l] += 1
			if f1 == 0:
				f1 = 1
			else:
				f1 = 0
		if f == 0:
			f = 1
		else:
			f = 0
	for item in arr:
		for ll in item:
			print(ll, end=' ')
		print('')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [list(map(int, input().split())) for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if a[i][j] & 1 != (i ^ j) & 1:
				a[i][j] += 1
	print('\n'.join((' '.join((str(y) for y in x)) for x in a)))


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	a = [list(map(int, input().split())) for i in range(r)]
	for i in range(r):
		for j in range(c):
			if i + j & 1:
				if a[i][j] & 1:
					pass
				else:
					a[i][j] += 1
			elif a[i][j] & 1:
				a[i][j] += 1
	for i in a:
		print(*i)


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

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

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

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

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, m) = inputnums()
	a = inputmatrixint(n)
	for i in range(n):
		for j in range(m):
			print(a[i][j] + (a[i][j] % 2 != (i + j) % 2), end=' ')
		print()


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	pr = []
	for i in range(n):
		l = list(map(int, input().split()))
		g = []
		f = 0
		for j in range(m):
			if i % 2 == 0:
				if j % 2 == 0:
					if l[j] % 2 == 0:
						g.append(l[j])
					else:
						g.append(l[j] + 1)
				elif l[j] % 2 == 0:
					g.append(l[j] + 1)
				else:
					g.append(l[j])
			elif j % 2 != 0:
				if l[j] % 2 == 0:
					g.append(l[j])
				else:
					g.append(l[j] + 1)
			elif l[j] % 2 == 0:
				g.append(l[j] + 1)
			else:
				g.append(l[j])
		pr.append(g)
	for j in pr:
		print(*j)


import sys
import heapq
import copy
import math
import decimal
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 insr2():
	s = input()
	s = list(s[:len(s) - 1])
	s = [ord(s[i]) - ord('a') for i in range(len(s))]
	return s

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

def pr_list(a):
	print(*a, sep=' ')

def solve():
	[n, m] = inlt()
	grid = []
	for i in range(n):
		a = inlt()
		grid.append(a)
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 != grid[i][j] % 2:
				grid[i][j] = grid[i][j] + 1
	for i in range(n):
		pr_list(grid[i])

def main():
	test = 1
	test = inp()
	for i in range(test):
		solve()
main()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	for i in range(n):
		a = list(map(int, input().split()))
		print(*[a[j] + (a[j] + i + j & 1) for j in range(m)])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = [list(map(int, input().split())) for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if (i + j) % 2 == 0 and ar[i][j] % 2 != 0:
				ar[i][j] += 1
			elif (i + j) % 2 == 1 and ar[i][j] % 2 != 1:
				ar[i][j] += 1
	for e in ar:
		print(*e)


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = [list(map(int, input().split())) for i in range(n)]
		for i in range(n):
			for j in range(m):
				a[i][j] += (i + j) % 2 != a[i][j] % 2
		for row in a:
			print(*row)
prog()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
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')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list()
	for i in range(n):
		b = list(map(int, input().split()))
		a.append(b)
	p = 0
	for i in range(n):
		p = 1 - p
		q = p
		for j in range(m):
			if a[i][j] % 2 != q:
				a[i][j] += 1
			q = 1 - q
	for i in range(n):
		print(*a[i])


import sys, functools, collections, bisect, math, heapq
input = sys.stdin.readline
mod = 1000000007
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().strip().split())
	mat = []
	for i in range(n):
		mat.append(list(map(int, input().strip().split())))
	newmat = [[0] * m for i in range(n)]
	for i in range(n):
		for j in range(m):
			if mat[i][j] % 2:
				newmat[i][j] = 1
	for i in range(n):
		for j in range(1, m):
			if newmat[i][j] == newmat[i][j - 1]:
				newmat[i][j] = 1 - newmat[i][j]
				mat[i][j] += 1
		if i < n - 1 and newmat[i][0] == newmat[i + 1][0]:
			newmat[i + 1][0] = 1 - newmat[i + 1][0]
			mat[i + 1][0] += 1
	for i in range(n):
		print(' '.join((str(j) for j in mat[i])))


from sys import stdin
from math import log2
input = lambda : stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	(n, m) = map(int, input().split())
	ans = [[0] * m for _ in range(n)]
	for i in range(n):
		lol = list(map(int, input().split()))
		ans[i] = lol
		for j in range(m):
			if ans[i][j] % 2 == (i + j) % 2:
				ans[i][j] += 1
	for i in range(n):
		print(*ans[i])