You are given two even integers $n$ and $m$. Your task is to find any binary matrix $a$ with $n$ rows and $m$ columns where every cell $(i,j)$ has exactly two neighbours with a different value than $a_{i,j}$.

Two cells in the matrix are considered neighbours if and only if they share a side. More formally, the neighbours of cell $(x,y)$ are: $(x-1,y)$, $(x,y+1)$, $(x+1,y)$ and $(x,y-1)$.

It can be proven that under the given constraints, an answer always exists.


-----Input-----

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The following lines contain the descriptions of the test cases.

The only line of each test case contains two even integers $n$ and $m$ ($2 \le n,m \le 50$) — the height and width of the binary matrix, respectively.


-----Output-----

For each test case, print $n$ lines, each of which contains $m$ numbers, equal to $0$ or $1$ — any binary matrix which satisfies the constraints described in the statement.

It can be proven that under the given constraints, an answer always exists.


-----Examples-----

Input
3
2 4
2 2
4 4
Output
1 0 0 1
0 1 1 0
1 0
0 1
1 0 1 0
0 0 1 1
1 1 0 0
0 1 0 1


-----Note-----

White means $0$, black means $1$.

The binary matrix from the first test case

The binary matrix from the second test case

The binary matrix from the third test case

Difficulty: EASY
Tags: Matrices

Bit manipulation

Constructive algorithms
Skill types: Bit manipulation

Starter code:

Solutions:
t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	s1 = '1'
	while True:
		s1 += '0'
		if len(s1) == m:
			break
		s1 += '0'
		if len(s1) == m:
			break
		s1 += '1'
		if len(s1) == m:
			break
		s1 += '1'
		if len(s1) == m:
			break
	s2 = ''
	for i in range(m):
		if s1[i] == '1':
			s2 += '0'
		else:
			s2 += '1'
	s1 = ' '.join(s1)
	s2 = ' '.join(s2)
	print(s1)
	n -= 1
	while True:
		if n == 0:
			break
		n -= 1
		print(s2)
		if n == 0:
			break
		n -= 1
		print(s2)
		if n == 0:
			break
		n -= 1
		print(s1)
		if n == 0:
			break
		n -= 1
		print(s1)


t = int(input())
for _ in range(t):
	(n, m) = input().split(' ')
	(n, m) = (int(n), int(m))
	(s1, s2) = ('', '')
	for i in range(m):
		if i % 4 == 0 or i % 4 == 3:
			s1 = s1 + '1 '
			s2 = s2 + '0 '
		else:
			s1 = s1 + '0 '
			s2 = s2 + '1 '
	for i in range(n):
		if i % 4 == 0 or i % 4 == 3:
			print(s1)
		else:
			print(s2)


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	row = [1, 0, 0, 1]
	while len(row) < m:
		row += [1, 0, 0, 1]
	if m % 4:
		row = row[:-2]
	row2 = [1 - x for x in row]
	row = ' '.join((str(x) for x in row))
	row2 = ' '.join((str(x) for x in row2))
	for _ in range(n // 4):
		print(row)
		print(row2)
		print(row2)
		print(row)
	if n % 4:
		print(row)
		print(row2)


import sys
input = sys.stdin.readline
t = int(input())
out = []
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	line1 = '1 0 0 1 ' * (m // 4)
	line2 = '0 1 1 0 ' * (m // 4)
	seq1 = [1, 0, 0, 1]
	seq2 = [0, 1, 1, 0]
	for i in range(m % 4):
		line1 += str(seq1[i]) + ' '
		line2 += str(seq2[i]) + ' '
	line1 += '\n'
	line2 += '\n'
	order = True
	for i in range(n // 2):
		if order:
			out.append(line1)
			out.append(line2)
		else:
			out.append(line2)
			out.append(line1)
		order = not order
print(''.join(out))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	st = '1 0 '
	st_m = '0 1 '
	one = ''
	two = ''
	for i in range(m // 2):
		if i % 2:
			one += st
			two += st_m
		else:
			one += st_m
			two += st
	if n == 2:
		print(one)
		print(two)
		continue
	for i in range(n // 2):
		if i % 2:
			print(one)
			print(two)
		else:
			print(two)
			print(one)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = '01'
	b = '10'
	ms = ''
	ns = ''
	for i in range(m // 2):
		if i % 2 == 0:
			ms = ms + a
			ns = ns + b
		else:
			ms = ms + b
			ns = ns + a
	for j in range(n // 2):
		if j % 2 == 0:
			print(' '.join(list(ms)))
			print(' '.join(list(ns)))
		else:
			print(' '.join(list(ns)))
			print(' '.join(list(ms)))


ncase = int(input())
for case in range(1, ncase + 1):
	(n, m) = [int(s) for s in input().split(' ')]
	flag = 0
	for i in range(n):
		if i % 4 == 0 or i % 4 == 3:
			if m % 4 == 0:
				print(' '.join(['1', '0', '0', '1'] * (m // 4)))
			else:
				print('1 0' + ' 0 1 1 0' * (m // 4))
		elif m % 4 == 0:
			print(' '.join(['0', '1', '1', '0'] * (m // 4)))
		else:
			print('0 1' + ' 1 0 0 1' * (m // 4))


for _ in range(int(input())):
	a = list(map(int, input().split()))
	for i in range(a[0]):
		if i % 4 == 0 or i % 4 == 3:
			print(int(a[1] / 4) * '1 0 0 1 ' + int(a[1] % 4 / 2) * '1 0')
		else:
			print(int(a[1] / 4) * '0 1 1 0 ' + int(a[1] % 4 / 2) * '0 1')


t = int(input())
while t > 0:
	(m, n) = list(map(int, input().split(' ')))
	c = ''
	d = ''
	a = '0 1'
	b = '1 0'
	for i in range(1, n // 2 + 1):
		if i % 2 == 0:
			c += b + ' '
			d += a + ' '
		else:
			c += a + ' '
			d += b + ' '
	for j in range(1, m // 2 + 1):
		if j % 2 == 0:
			print(c)
			print(d)
		else:
			print(d)
			print(c)
	t -= 1


import sys

def solve():
	(n, m) = map(int, sys.stdin.readline().split())
	pattern1 = '1 0 0 1 '
	pattern2 = '0 1 1 0 '
	remainder = m % 4 * 2
	quotient = m // 4
	pattern1 = pattern1 * quotient + pattern1[:remainder]
	pattern2 = pattern2 * quotient + pattern2[:remainder]
	pattern_type = False
	sys.stdout.write(pattern1 + '\n')
	x = 0
	for i in range(1, n):
		x += 1
		if pattern_type:
			sys.stdout.write(pattern1 + '\n')
		else:
			sys.stdout.write(pattern2 + '\n')
		if x == 2:
			pattern_type = not pattern_type
			x = 0

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		solve()
main()


tc = int(input())
while tc > 0:
	A = [int(i) for i in input().split(' ')]
	R1 = ['0', '1']
	R2 = ['1', '0']
	L1 = ['1', '0']
	L2 = ['0', '1']
	R3 = ['1', '0']
	R4 = ['0', '1']
	L3 = ['0', '1']
	L4 = ['1', '0']
	n = A[0] // 2
	m = A[1] // 2
	ans = []
	for i in range(n):
		curr1 = []
		curr2 = []
		if i % 2 == 0:
			for j in range(m):
				if j % 2 == 0:
					curr1 += R1
					curr2 += R2
				else:
					curr1 += L1
					curr2 += L2
		else:
			for j in range(m):
				if j % 2 == 0:
					curr1 += R3
					curr2 += R4
				else:
					curr1 += L3
					curr2 += L4
		ans = ans + [curr1] + [curr2]
	for i in range(2 * n):
		print(' '.join(ans[i]))
	tc = tc - 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	for i in range(n // 4):
		print('1 0 0 1 ' * (m // 4) + '1 0' * (m % 4 // 2))
		print('0 1 1 0 ' * (m // 4) + '0 1' * (m % 4 // 2))
		print('0 1 1 0 ' * (m // 4) + '0 1' * (m % 4 // 2))
		print('1 0 0 1 ' * (m // 4) + '1 0' * (m % 4 // 2))
	if n % 4 == 2:
		print('1 0 0 1 ' * (m // 4) + '1 0' * (m % 4 // 2))
		print('0 1 1 0 ' * (m // 4) + '0 1' * (m % 4 // 2))


num_of_matrixes = int(input())
dimensions = [tuple(map(int, input().split())) for _ in range(num_of_matrixes)]

def print_matrix(n, m):
	block_width = m // 2
	block_height = n // 2
	big_result = []
	for row in range(block_height):
		unit1 = '1 0 '
		unit2 = '0 1 '
		str_1 = []
		str_2 = []
		for column in range(block_width):
			if row % 2 == 0:
				str_1.append(unit1)
				str_2.append(unit2)
			else:
				str_1.append(unit2)
				str_2.append(unit1)
			(unit1, unit2) = (unit2, unit1)
		big_result.append(''.join(str_1)[:-1])
		big_result.append(''.join(str_2)[:-1])
	for line in big_result:
		print(line)
for item in dimensions:
	print_matrix(*item)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = '11'
	B = '00'
	row1 = []
	row2 = []
	for i in range(m // 2):
		if i % 2 == 0:
			row1.append(A)
			row2.append(B)
		else:
			row1.append(B)
			row2.append(A)
	row1 = ''.join(row1)
	row2 = ''.join(row2)
	if row1[-1] == '0':
		row1 = row1[1:] + '1'
	else:
		row1 = row1[1:] + '0'
	if row2[-1] == '0':
		row2 = row2[1:] + '1'
	else:
		row2 = row2[1:] + '0'
	col = []
	for i in range(n // 2):
		if i % 2 == 0:
			col.append(A)
		else:
			col.append(B)
	col = ''.join(col)
	if col[-1] == '0':
		col = col[1:] + '1'
	else:
		col = col[1:] + '0'
	for el in col:
		if el == '1':
			print(' '.join(row1))
		else:
			print(' '.join(row2))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	pairs = ['1 0 ', '0 1 ']
	rows = ['', '']
	for i in range(m // 2):
		rows[0] += pairs[i % 2]
		rows[1] += pairs[i % 2 - 1]
	pair_rows = [rows[0] + '\n' + rows[1] + '\n', rows[1] + '\n' + rows[0] + '\n']
	matrix = ''
	for i in range(n // 2):
		matrix += pair_rows[i % 2]
	print(matrix.strip())


for i in range(int(input())):
	(n, m) = map(int, input().split())
	m //= 2
	n //= 2
	s = '1 ' + '0 0 1 1 ' * ((m - 1) // 2)
	if m % 2 == 0:
		s += '0 0 1'
	else:
		s += '0'
	print(s)
	s1 = ''.join(({'0': '1', '1': '0', ' ': ' '}[c] for c in s))
	print((s1 + '\n' + s1 + '\n' + s + '\n' + s + '\n') * ((n - 1) // 2), end='')
	if n % 2:
		print(s1)
	else:
		print(s1 + '\n' + s1 + '\n' + s)


t = int(input())
for z in range(t):
	(n, m) = [int(x) for x in input().split()]
	l1 = [1, 0]
	l2 = [0, 1]
	p = []
	q = []
	s = ''
	r = ''
	for i in range(m // 2):
		if i % 2 == 0:
			p = p + l1
			q = q + l2
		else:
			p = p + l2
			q = q + l1
	for i in p:
		x = str(i)
		s = s + x + ' '
	for i in q:
		y = str(i)
		r = r + y + ' '
	print(s)
	for i in range((n - 2) // 2):
		if i % 2 == 0:
			print(r)
			print(r)
		else:
			print(s)
			print(s)
	if n % 4 == 0:
		print(s)
	else:
		print(r)


a = int(input())
for i in range(a):
	b = list(map(int, input().split()))
	row = b[1]
	main = '1 0 0 1 '
	st = ''
	de = row % 4
	se = row // 4
	st += main * se
	if de == 1:
		st += '1'
	if de == 2:
		st += '1 0'
	if de == 3:
		st += '1 0 0'
	column = st.replace('0', '2')
	column = column.replace('1', '0')
	column = column.replace('2', '1')
	m = 1
	final = ''
	for k in range(b[0]):
		if k % 2 != 0:
			final += st + '\n'
			m = 1
		else:
			final += column + '\n'
			m = 0
		if m == 1:
			sd = st
			st = column
			column = sd
	print(final[:-1])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	pt1 = [1, 0]
	pt2 = [0, 1]
	save1 = []
	save2 = []
	p1 = ''
	p2 = ''
	for i in range(m // 2):
		if i % 2 == 0:
			save1 += pt1
			save2 += pt2
		else:
			save1 += pt2
			save2 += pt1
	p1 = ' '.join(map(str, save1))
	p2 = ' '.join(map(str, save2))
	print(p1)
	for i in range((n - 2) // 2):
		if i % 2 == 0:
			print(p2)
			print(p2)
		else:
			print(p1)
			print(p1)
	if n % 4 == 0:
		print(p1)
	else:
		print(p2)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if m % 4 == 0:
		first = '0 1 1 0 ' * (m // 4)
		second = '1 0 0 1 ' * (m // 4)
	elif m == 2:
		first = '0 1'
		second = '1 0'
	else:
		first = '0 1 1 0 ' * (m // 4) + '0 1 '
		second = '1 0 0 1 ' * (m // 4) + '1 0 '
	if n % 4 != 0:
		print(first)
		for i in range((n - 2) // 4):
			print(second)
			print(second)
			print(first)
			print(first)
		print(second)
	else:
		print(first)
		for i in range((n - 4) // 4):
			print(second)
			print(second)
			print(first)
			print(first)
		print(second)
		print(second)
		print(first)


def criarMatriz(n, m):
	padrao1 = '1 0 '
	padrao2 = '0 1 '
	cntlin = True
	cntCol = 0
	linhaMult3 = ''
	outrasLinhas = ''
	for i in range(m // 2):
		if cntlin:
			linhaMult3 += padrao1
			outrasLinhas += padrao2
		else:
			linhaMult3 += padrao2
			outrasLinhas += padrao1
		cntlin = not cntlin
	linhaMult3 = linhaMult3.strip()
	outrasLinhas = outrasLinhas.strip()
	for i in range(n):
		if i % 4 == 0 or i % 4 == 3:
			print(linhaMult3)
		else:
			print(outrasLinhas)
numCase = int(input())
for i in range(numCase):
	nm = list(map(int, input().split(' ')))
	criarMatriz(nm[0], nm[1])


def generate_line(current, columns):
	line = []
	for _ in range(columns // 2):
		if current:
			line += '1'
			line += '0'
		else:
			line += '0'
			line += '1'
		current = not current
	return ' '.join(line)
n = int(input())
for _ in range(n):
	(rows, columns) = [int(x) for x in input().split()]
	for row in range(rows // 2):
		start = True
		if row % 2 != 0:
			start = False
		print(generate_line(start, columns))
		print(generate_line(not start, columns))


t = int(input())
for _ in range(t):
	(h, w) = map(int, input().split())
	a = ''
	b = ''
	for i in range(1, w // 2 + 1):
		if i % 2 == 0:
			a += '1 0 '
			b += '0 1 '
		else:
			a += '0 1 '
			b += '1 0 '
	for i in range(1, h // 2 + 1):
		if i % 2 == 0:
			print(b)
			print(a)
		else:
			print(a)
			print(b)


t = int(input())
for _ in range(t):
	(n, m) = (int(ii) for ii in input().split())
	(a, b) = ('0 1', '1 0')
	for i in range(m // 2 - 1):
		if i % 2 == 0:
			a += ' 1 0'
			b += ' 0 1'
		else:
			a += ' 0 1'
			b += ' 1 0'
	for j in range(n // 2):
		if j % 2 == 0:
			print(a)
			print(b)
		else:
			print(b)
			print(a)


n = int(input())
while n:
	(a, b) = map(int, input().split())
	row = [0]
	for i in range(b // 2 - 1):
		row.append((row[-1] + 1) % 2)
	for i in range(a // 2):
		output = [[], []]
		nrow = []
		for v in row:
			if v == 0:
				output[0] += ['0', '1']
				output[1] += ['1', '0']
				nrow.append(1)
			else:
				output[1] += ['0', '1']
				output[0] += ['1', '0']
				nrow.append(0)
		print(' '.join(output[0]))
		print(' '.join(output[1]))
		row = nrow
	n -= 1


for i in range(int(input())):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	inversed = False
	for k in range(int(n / 2)):
		if inversed:
			s = ''
			for j in range(int(m / 2)):
				if j % 2 == 0:
					s = s + '1 0 '
				else:
					s = s + '0 1 '
			print(s[:-1])
			s = ''
			for j in range(int(m / 2)):
				if j % 2 == 0:
					s = s + '0 1 '
				else:
					s = s + '1 0 '
			print(s[:-1])
			inversed = False
		else:
			s = ''
			for j in range(int(m / 2)):
				if j % 2 == 0:
					s = s + '0 1 '
				else:
					s = s + '1 0 '
			print(s[:-1])
			s = ''
			for j in range(int(m / 2)):
				if j % 2 == 0:
					s = s + '1 0 '
				else:
					s = s + '0 1 '
			print(s[:-1])
			inversed = True


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	pat1 = [1, 0]
	pat2 = [0, 1]
	cur1 = []
	for j in range(0, m, 2):
		cur1 += pat1
		pat1 = pat1[::-1]
	cur2 = []
	for j in range(0, m, 2):
		cur2 += pat2
		pat2 = pat2[::-1]
	ans = []
	ans.append(cur1)
	path = -1
	for i in range(1, n - 1, 2):
		ans.append(cur1 if path == 1 else cur2)
		ans.append(cur1 if path == 1 else cur2)
		path *= -1
	ans.append(cur1 if n % 4 == 0 else cur2)
	for row in ans:
		print(' '.join([str(i) for i in row]))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	pattern = [[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]]
	repeatHor = m // 4
	extraHor = False
	if m % 4 == 2:
		extraHor = True
	repeatVert = n // 4
	extraVert = False
	if n % 4 == 2:
		extraVert = True
	line1 = '0 1 1 0 ' * repeatHor
	if extraHor:
		line1 += '0 1'
	line2 = '1 0 0 1 ' * repeatHor
	if extraHor:
		line2 += '1 0'
	line3 = '1 0 0 1 ' * repeatHor
	if extraHor:
		line3 += '1 0'
	line4 = '0 1 1 0 ' * repeatHor
	if extraHor:
		line4 += '0 1'
	for i in range(repeatVert):
		print(line1)
		print(line2)
		print(line3)
		print(line4)
	if extraVert:
		print(line1)
		print(line2)


t = int(input())
while t:
	t = t - 1
	(n, m) = map(int, input().split())
	res = []
	for j in range(2):
		st = ''
		for i in range(m):
			if j == 0:
				ff = '1 '
			else:
				ff = '0 '
			if i == 0:
				st += ff
				if ff == '1 ':
					ss = '0 '
				else:
					ss = '1 '
				cnt = 0
			else:
				if cnt == 2:
					if ss == '0 ':
						ss = '1 '
					else:
						ss = '0 '
					cnt = 0
				st += ss
				cnt += 1
		st = st.strip()
		res.append(st)
	mat = []
	for i in range(n):
		if i == 0:
			mat.append(res[0])
			cnt = 0
			cc = 1
		else:
			if cnt == 2:
				if cc == 1:
					cc = 0
				else:
					cc = 1
				cnt = 0
			mat.append(res[cc])
			cnt += 1
	for i in mat:
		print(i)


def task(n, m):
	grid = []
	for i in range(0, n):
		row = []
		for j in range(0, m):
			a = i % 4
			b = j % 4
			if a == b or b + a == 3:
				row.append('1')
			else:
				row.append('0')
		print(' '.join(row))
t = int(input())
for i in range(0, t):
	(n, m) = list(map(int, input().split()))
	task(n, m)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	p = '1'
	pp = '0'
	s1 = ''
	s2 = ''
	for i in range(m):
		if pp == '0' and p == '1':
			s1 += ' 1'
			pp = '1'
		elif pp == '0' and p == '0':
			s1 += ' 1'
			p = '1'
		elif pp == '1' and p == '0':
			s1 += ' 0'
			pp = '0'
		elif pp == '1' and p == '1':
			s1 += ' 0'
			p = '0'
	p = '0'
	pp = '1'
	for i in range(m):
		if pp == '0' and p == '1':
			s2 += ' 1'
			pp = '1'
		elif pp == '0' and p == '0':
			s2 += ' 1'
			p = '1'
		elif pp == '1' and p == '0':
			s2 += ' 0'
			pp = '0'
		elif pp == '1' and p == '1':
			s2 += ' 0'
			p = '0'
	p = '1'
	pp = '0'
	s1 = s1.strip()
	s2 = s2.strip()
	for i in range(n):
		if pp == '0' and p == '1':
			print(s1)
			pp = '1'
		elif pp == '0' and p == '0':
			print(s1)
			p = '1'
		elif pp == '1' and p == '0':
			print(s2)
			pp = '0'
		elif pp == '1' and p == '1':
			print(s2)
			p = '0'


b = {0: [['1', '0'], ['0', '1']], 1: [['0', '1'], ['1', '0']]}
t = int(input().strip())
for _ in range(t):
	(n, m) = [int(i) for i in input().strip().split()]
	for i in range(n // 2):
		l = i % 2
		l1 = []
		l2 = []
		for j in range(m // 2):
			s = b[(l + j) % 2]
			l1 += s[0]
			l2 += s[1]
		print(' '.join(l1))
		print(' '.join(l2))


def main():
	seq = '1001'
	ps = [0, 2, 2, 0]
	N = int(input())
	for _ in range(N):
		(h, w) = map(int, input().split())
		mat = [[None] * w for _ in range(h)]
		for r in range(h):
			i = ps[r % 4]
			c = 0
			while c < w:
				mat[r][c] = seq[i]
				c += 1
				i = (i + 1) % len(seq)
		for r in range(h):
			print(' '.join(mat[r]))

def init():
	import os
	import sys
	sys.setrecursionlimit(2 * 10 ** 6)
	if 'CP_LOCAL_ENV' in os.environ:
		sys.stdin = open('cf_test_b.txt')
init()
main()


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	pat1 = [1, 0]
	pat2 = [0, 1]
	r1 = (pat1 + pat2) * (n // 4) + pat1 * (n % 4 == 2)
	r2 = (pat2 + pat1) * (n // 4) + pat2 * (n % 4 == 2)
	for i in range(m):
		if i % 4 == 1 or i % 4 == 2:
			print(' '.join(map(str, r2)))
		else:
			print(' '.join(map(str, r1)))


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


import sys
import string
from decimal import Decimal
from math import log

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

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

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

def invr():
	return map(int, input().split())
t = int(input())
for _ in range(t):
	(n, m) = invr()
	first = '1 0 0 1 ' * 20
	second = '0 1 1 0 ' * 20
	third = '0 1 1 0 ' * 20
	fourth = '1 0 0 1 ' * 20
	for i in range(n):
		if i % 4 == 0:
			print(first[:2 * m])
		elif i % 4 == 1:
			print(second[:2 * m])
		elif i % 4 == 2:
			print(third[:2 * m])
		else:
			print(fourth[:2 * m])


for _ in range(int(input())):
	(m, n) = [int(a) for a in input().split()]
	arr = [['0'] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			if i % 4 in [0, 3] and j % 4 in [0, 3] or (i % 4 in [1, 2] and j % 4 in [1, 2]):
				arr[i][j] = '1'
		print(' '.join(arr[i]))


import sys
d = (((0, 0), (1, 1)), ((1, 0), (0, 1)))
inputs = sys.stdin.readlines()
for i in range(1, len(inputs)):
	(n, m) = map(int, inputs[i].split())
	board = [['0' for _ in range(m)] for _ in range(n)]
	for i in range(0, n, 2):
		di = i // 2 % 2
		for j in range(0, m, 2):
			for dd in d[di]:
				board[i + dd[0]][j + dd[1]] = '1'
			di = (di + 1) % 2
	for b in board:
		sys.stdout.write(' '.join(b) + '\n')


def solve():
	odd_pattern = [1, 0, 0, 1]
	even_pattern = [0, 1, 1, 0]
	row_pattern = [1, 0, 0, 1]
	num_tests = int(input())
	for t in range(num_tests):
		(rows, cols) = map(int, input().split())
		if rows == 2 and cols == 2:
			print('1 0')
			print('0 1')
		else:
			for n in range(rows):
				new_row = []
				for m in range(cols):
					if row_pattern[n % 4] == 1:
						num = even_pattern[m % 4]
					else:
						num = odd_pattern[m % 4]
					new_row.append(str(num))
				print(' '.join(new_row))
solve()


n = int(input())
test_cases = []
for i in range(n):
	test_cases.append([int(i) for i in input().split()])
for test_case in test_cases:
	(l, m) = test_case
	matrix = [[0 for _ in range(m)] for _ in range(l)]
	matrix[0][0] = 1
	matrix[1][1] = 1
	for i in range(1, int(m / 2)):
		matrix[0][1 + i * 2] = matrix[0][(i - 1) * 2]
		matrix[1][0 + i * 2] = matrix[1][(i - 1) * 2 + 1]
		matrix[1][1 + i * 2] = matrix[1][(i - 1) * 2]
		matrix[0][0 + i * 2] = matrix[0][(i - 1) * 2 + 1]
	for i in range(1, int(l / 2)):
		matrix[i * 2] = matrix[(i - 1) * 2 + 1]
		matrix[i * 2 + 1] = matrix[(i - 1) * 2]
	for i in range(len(matrix)):
		print(' '.join(map(str, matrix[i])))


def solve():
	(n, m) = map(int, input().split())
	ans = [[0] * m for _ in range(n)]
	for i in range(0, n, 2):
		for j in range(0, m, 2):
			if (i // 2 + j // 2) % 2 == 0:
				ans[i + 1][j] = 1
				ans[i][j + 1] = 1
			else:
				ans[i][j] = 1
				ans[i + 1][j + 1] = 1
	for a in ans:
		print(' '.join((str(x) for x in a)))
for _ in range(int(input())):
	solve()


t = int(input())
pattern1 = [1, 0, 0, 1] * 20
pattern2 = [0, 1, 1, 0] * 20

def f(m, n):
	for i in range(m):
		l = pattern1[:n] if i % 4 in [0, 3] else pattern2[:n]
		print(' '.join(map(str, l)))
for _ in range(t):
	(m, n) = map(int, input().split())
	f(m, n)


import io, os, sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	row = [1, 0]
	for j in range(2, m):
		if j % 2 == 0:
			row.append(row[-1])
		else:
			row.append(row[-1] ^ 1)
	for i in range(n):
		print(' '.join([str(r) for r in row]))
		if i % 2 == 0:
			row = [r ^ 1 for r in row]


testcases = int(input())
for _ in range(testcases):
	(cols, rows) = list(map(int, input().split()))
	ans = [[0 for i in range(rows)] for j in range(cols)]
	column = len(ans[0])
	rows = len(ans)
	for row in range(0, rows, 2):
		for col in range(0, column, 2):
			if (row + col) % 4 == 0:
				ans[row][col] = str(0)
				ans[row + 1][col] = str(1)
				ans[row][col + 1] = str(1)
				ans[row + 1][col + 1] = str(0)
			else:
				ans[row][col] = str(1)
				ans[row + 1][col] = str(0)
				ans[row][col + 1] = str(0)
				ans[row + 1][col + 1] = str(1)
	ans = [' '.join(num) for num in ans]
	print('\n'.join(ans))


tests = int(input())
for i in range(0, tests):
	(n, m) = map(int, input().split()[:2])
	board = list()
	count = 0
	turn = 1
	for t in range(0, n):
		new_line = list()
		for i in range(0, int(m / 2)):
			if t == 0 or turn == 0:
				if i % 2 == 0:
					new_line.append(0)
					new_line.append(1)
				else:
					new_line.append(1)
					new_line.append(0)
			elif i % 2 == 0:
				new_line.append(1)
				new_line.append(0)
			else:
				new_line.append(0)
				new_line.append(1)
		if t == 0 or count <= 2:
			count = count + 1
		if count > 2:
			if turn == 1:
				turn = 0
			else:
				turn = 1
			count = 1
		board.append(new_line)
	for j in board:
		print(' '.join(map(str, j)))


a = int(input())
ju = [[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]
for i in range(a):
	(n, m) = map(int, input().split())
	for j in range(n):
		ans = []
		for k in range(m):
			ans.append(str(ju[j % 4][k % 4]))
		print(' '.join(ans))


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = [int(i) for i in input().split()]
	k = 0
	p = 0
	if n >= 4:
		for i in range(0, n // 4, 1):
			if m >= 4:
				for j in range(0, m // 4, 1):
					print('1 0 0 1 ', end='')
			if m % 4 != 0:
				print('1 0 ', end='')
			print('\n')
			if m >= 4:
				for j in range(0, m // 4, 1):
					print('0 1 1 0 ', end='')
			if m % 4 != 0:
				print('0 1 ', end='')
			print('\n')
			if m >= 4:
				for j in range(0, m // 4, 1):
					print('0 1 1 0 ', end='')
			if m % 4 != 0:
				print('0 1 ', end='')
			print('\n')
			if m >= 4:
				for j in range(0, m // 4, 1):
					print('1 0 0 1 ', end='')
			if m % 4 != 0:
				print('1 0 ', end='')
			print('\n')
	if n % 4 != 0:
		if m >= 4:
			for j in range(0, m // 4, 1):
				print('1 0 0 1 ', end='')
		if m % 4 != 0:
			print('1 0 ', end='')
		print('\n')
		if m >= 4:
			for j in range(0, m // 4, 1):
				print('0 1 1 0 ', end='')
		if m % 4 != 0:
			print('0 1 ', end='')
		print('\n')


def GenerateMatrix(n, m):
	matrix = list()
	baseMatrix = [[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]]
	for i in range(n):
		matrix.append(list())
		for j in range(m):
			matrix[i].append(baseMatrix[i % 4][j % 4])
	return matrix

def ShowMatrix(matrix):
	for i in range(len(matrix)):
		print(' '.join([str(el) for el in matrix[i]]))

def GetNeigboursCount(matrix, i, j):
	n = len(matrix)
	m = len(matrix[0])
	own = matrix[i][j]
	count = 0
	if i - 1 >= 0 and matrix[i - 1][j] != own:
		count += 1
	if i + 1 < n and matrix[i + 1][j] != own:
		count += 1
	if j - 1 >= 0 and matrix[i][j - 1] != own:
		count += 1
	if j + 1 < m and matrix[i][j + 1] != own:
		count += 1
	return count

def CheckMatrix(matrix):
	n = len(matrix)
	m = len(matrix[0])
	newMatrix = matrix
	for i in range(n):
		for j in range(m):
			if GetNeigboursCount(matrix, i, j) != 2:
				newMatrix[i][j] = 3 if matrix[i][j] == 0 else 4
	ShowMatrix(newMatrix)
n = int(input())
for i in range(n):
	(x, y) = [int(i) for i in input().split()]
	matrix = GenerateMatrix(x, y)
	ShowMatrix(matrix)


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

def kil_(nm):
	(n, m) = nm
	AA = ''
	for i in range(n):
		A = ''
		for j in range(m):
			if j % 2 == (i + int(j / 2) + int(i / 2)) % 2:
				A += '1' + ' '
			else:
				A += '0' + ' '
		AA += A[:-1] + '\n'
	return AA[:-1]

def kil(a):
	t = int(input())
	A = ''
	for i in range(t):
		A += kil_(a()) + '\n'
	print(A[:-1])
kil(fu)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	a //= 2
	b //= 2
	l = ['1 0', '0 1', '0 1', '1 0']
	for i in range(2 * a):
		for j in range(b):
			print(l[(i + 2 * j) % 4], end=' ')
		print()


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


C = int(input())
while C:
	(n, m) = map(int, input().split())
	board = [[0 for c in range(m)] for r in range(n)]
	for i in range(n):
		for j in range(m):
			if i == 0:
				if j % 4 == 0 or j % 4 == 3:
					board[i][j] = '1'
				else:
					board[i][j] = '0'
			elif i % 2 == 1:
				if board[i - 1][j] == '1':
					board[i][j] = '0'
				else:
					board[i][j] = '1'
			elif i % 2 == 0:
				if board[i - 1][j] == '0':
					board[i][j] = '0'
				else:
					board[i][j] = '1'
		print(' '.join(board[i]))
	C -= 1


T = int(input())
for t in range(T):
	(r, c) = map(int, input().split())
	marker = 0
	mark = [None] * r
	mark[0] = marker
	start = 0
	r_marker = 1 - marker
	for i in range(1, r - 1):
		if start < 2:
			mark[i] = r_marker
			start += 1
		else:
			r_marker = 1 - r_marker
			mark[i] = r_marker
			start = 1
	mark[-1] = 1 - mark[-2]
	for i in range(r):
		result = [None] * c
		result[0] = str(mark[i])
		r_start = 0
		r_marker = 1 - mark[i]
		for j in range(1, c - 1):
			if r_start < 2:
				result[j] = str(r_marker)
				r_start += 1
			else:
				r_marker = 1 - r_marker
				result[j] = str(r_marker)
				r_start = 1
		result[-1] = str(1 - int(result[-2]))
		print(' '.join(result))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	for j in range(a):
		for k in range(b // 2):
			if (j % 4 == 0 or j % 4 == 3) and k % 2 == 0 or ((j % 4 == 2 or j % 4 == 1) and k % 2 == 1):
				print('1 0', end=' ')
			else:
				print('0 1', end=' ')
		print()


test = int(input())
a = '0 1'
b = '1 0'
for i in range(test):
	[height, length] = map(int, input().split())
	dd = 0
	for k in range(height):
		if k % 2 != 0:
			dd += 1
		for j in range(int(length / 2)):
			if (j + dd) % 2 == 0:
				print(a, end=' ')
				continue
			print(b, end=' ')
		print()


t = int(input())
for _ in range(t):
	(n, m) = [int(x) // 2 for x in input().split()]
	sub_matrix_even = ['1 0 ', '0 1 ']
	sub_matrix_odd = ['0 1 ', '1 0 ']
	for j in range(n):
		for i in range(m):
			if (i + j) % 2 == 0:
				print(sub_matrix_even[0], end='')
			else:
				print(sub_matrix_odd[0], end='')
		print()
		for i in range(m):
			if (i + j) % 2 == 0:
				print(sub_matrix_even[1], end='')
			else:
				print(sub_matrix_odd[1], end='')
		print()


t = int(input())
options = [[[1, 0], [0, 1]], [[0, 1], [1, 0]]]
for _ in range(t):
	[n, m] = [int(c) for c in input().split()]
	ans = [[0 for _ in range(m)] for _ in range(n)]
	for i in range(0, n, 2):
		for j in range(0, m, 2):
			op = options[int((i / 2 + j / 2) % 2)]
			ans[i][j:j + 2] = op[0]
			ans[i + 1][j:j + 2] = op[1]
	for row in ans:
		print(' '.join([str(a) for a in row]))


for _ in range(int(input())):
	(n, m) = [int(_) for _ in input().split()]
	ten = '1 0'
	one = '0 1'
	for i in range(0, n, 2):
		if i % 4 == 0 or i % 4 == 3:
			for j in range(0, m // 2):
				if j % 2 == 0:
					print(ten, end=' ')
				else:
					print(one, end=' ')
			print()
			for j in range(0, m // 2):
				if j % 2 == 0:
					print(one, end=' ')
				else:
					print(ten, end=' ')
			print()
		else:
			for j in range(0, m // 2):
				if j % 2 == 0:
					print(one, end=' ')
				else:
					print(ten, end=' ')
			print()
			for j in range(0, m // 2):
				if j % 2 == 0:
					print(ten, end=' ')
				else:
					print(one, end=' ')
			print()


t = int(input())
for _ in range(t):
	(row, col) = list(map(int, input().split()))
	for j in range(row // 2):
		if j % 2 == 0:
			group = col // 2
			i = 0
			while group:
				if i % 2 == 0:
					print('1 0', end=' ')
				else:
					print('0 1', end=' ')
				i += 1
				group -= 1
			print()
			group = col // 2
			i = 0
			while group:
				if i % 2 == 0:
					print('0 1', end=' ')
				else:
					print('1 0', end=' ')
				i += 1
				group -= 1
			print()
		else:
			group = col // 2
			i = 0
			while group:
				if i % 2 == 0:
					print('0 1', end=' ')
				else:
					print('1 0', end=' ')
				i += 1
				group -= 1
			print()
			group = col // 2
			i = 0
			while group:
				if i % 2 == 0:
					print('1 0', end=' ')
				else:
					print('0 1', end=' ')
				i += 1
				group -= 1
			print()


t = int(input().strip())
for _ in range(t):
	(n, m) = map(int, input().split())
	half_m = m // 2
	for i in range(n):
		if i % 4 == 0 or i % 4 == 3:
			for j in range(half_m):
				if j % 2:
					print('0 1', end=' ')
				else:
					print('1 0', end=' ')
		else:
			for j in range(half_m):
				if j % 2:
					print('1 0', end=' ')
				else:
					print('0 1', end=' ')
		print('')


t = int(input())
for x in range(t):
	(h, w) = map(int, input().split())
	for a in range(1, h + 1):
		str_ = ''
		for b in range(1, w + 1):
			str_ += str(int((a % 4 <= 1) != (b % 4 <= 1))) + ' '
		print(str_)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	c1 = 2
	for i in range(n):
		ans = ''
		if c1 > 2:
			start = 0
		else:
			start = 1
		c2 = 2
		for j in range(m):
			if c2 > 2:
				ans += str(abs(start - 1))
			else:
				ans += str(start)
			ans += ' '
			c2 += 1
			if c2 > 4:
				c2 = 1
		c1 += 1
		if c1 > 4:
			c1 = 1
		print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	for i in range(1, n + 1):
		for j in range(m // 2):
			c = j + i // 2
			if c % 2:
				print('1 0', end=' ')
			else:
				print('0 1', end=' ')
		print()


import math

def func():
	(n, m) = map(int, input().split())
	l1 = [1, 0, 0, 1]
	l2 = [0, 1, 1, 0]
	l1 *= math.ceil(m / 4)
	l2 *= math.ceil(m / 4)
	l1 = l1[:m]
	l2 = l2[:m]
	f = 0
	for i in range(n // 2):
		if not f:
			print(*l1)
			print(*l2)
			f = 1
		else:
			print(*l2)
			print(*l1)
			f = 0
t = int(input())
for _ in range(t):
	func()


t = int(input())
nm_list = []
for i in range(t):
	nm_list.append([int(elm) for elm in input().split(' ')])
array_list = []
for nm in nm_list:
	x = [[0] * nm[1] for i in range(nm[0])]
	c_n = 1
	for i in range(nm[0]):
		c_m = c_n
		for j in range(nm[1]):
			x[i][j] = str(c_m)
			if j % 2 == 0:
				c_m = -(c_m - 1)
		if i % 2 == 0:
			c_n = -(c_n - 1)
	array_list.append(x)
for array in array_list:
	for i in range(len(array)):
		print(' '.join([str(elm) for elm in array[i]]))


testcases = int(input())
for i in range(testcases):
	(n, m) = map(int, input().split())
	li = []
	a1 = []
	a2 = []
	for k in range(m):
		if k == 0:
			a1.append(1)
		elif (k + 1) % 4 == 0 or k % 4 == 0:
			a1.append(1)
		else:
			a1.append(0)
	for s in range(m):
		if s == 0:
			a2.append(0)
		elif (s + 1) % 4 == 0 or s % 4 == 0:
			a2.append(0)
		else:
			a2.append(1)
	for p in range(n):
		if p == 0:
			print(*a1)
		elif p % 4 == 0 or (p + 1) % 4 == 0:
			print(*a1)
		else:
			print(*a2)


n = int(input())
arr = []
res = []
try:
	while n > 0:
		string = [int(x) for x in input().split()]
		if string:
			arr.append(string)
			n -= 1
except Exception:
	pass

def fnc(x):
	res = []
	for i in range(x[0]):
		res.append([])
		for j in range(x[1]):
			if i == 0 and j == 0:
				res[i].append(1)
			elif i == 1 and j == 0:
				res[i].append(0)
			elif j == 0:
				if res[i - 1][0] == 0 and res[i - 2][0] == 1 or (res[i - 1][0] == 1 and res[i - 2][0] == 1):
					res[i].append(0)
				else:
					res[i].append(1)
			elif i == 0 and j == 1:
				res[i].append(0)
			elif i == 1 and j == 0:
				res[i].append(1)
			elif res[i][j - 1] == 0 and res[i][j - 2] == 1 or (res[i][j - 1] == 1 and res[i][j - 2] == 1):
				res[i].append(0)
			else:
				res[i].append(1)
	return res

def printRes(res):
	for x in range(len(res)):
		print(' '.join(list(map(str, res[x]))))
for x in range(len(arr)):
	printRes(fnc(arr[x]))


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	a = [1, 0, 0, 1]
	b = [0, 1, 1, 0]
	k = n // 4
	r = n % 4
	a = a * k + a[:r]
	b = b * k + b[:r]
	for i in range(1, m + 1):
		if i % 4 == 1 or i % 4 == 0:
			print(*a)
		else:
			print(*b)


l = int(input())
for i in range(l):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	mtx = [[-1 for i in range(m)] for j in range(n)]
	mtx[0][0] = 1
	indexA = 0
	for a in range(n - 1):
		add = [0, 1]
		mtx[1 + a][0] = add[indexA % 2]
		if (a + 1) % 2 == 0:
			indexA += 1
	for c in range(n):
		indexB = 0
		for b in range(m - 1):
			if mtx[c][0] == 1:
				add = [0, 1]
				mtx[c][1 + b] = add[indexB % 2]
				if (b + 1) % 2 == 0:
					indexB += 1
			else:
				add = [1, 0]
				mtx[c][1 + b] = add[indexB % 2]
				if (b + 1) % 2 == 0:
					indexB += 1
		indexB = 0
	for k in range(n):
		result = ' '.join((str(item) for item in mtx[k]))
		print(result)


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	check = True
	ans = []
	a1 = []
	a2 = []
	for i in range(0, m, 2):
		if check:
			a1.append(0)
			a1.append(1)
			a2.append(1)
			a2.append(0)
			check = False
		else:
			a1.append(1)
			a1.append(0)
			a2.append(0)
			a2.append(1)
			check = True
	check = True
	for i in range(0, n, 2):
		if check:
			ans.append(a1)
			ans.append(a2)
			check = False
		else:
			ans.append(a2)
			ans.append(a1)
			check = True
	for i in ans:
		print(*i)


import sys
t = int(sys.stdin.readline())
for i in range(t):
	(n, m) = map(int, input().split())
	q = m // 4
	r = m % 4
	s1 = ''
	for j in range(q):
		s1 += '1001'
	if r > 0:
		s1 += '10'
	s0 = ''
	for j in range(q):
		s0 += '0110'
	if r > 0:
		s0 += '01'
	q1 = n // 4
	r1 = n % 4
	ans = []
	for j in range(q1):
		ans.append(s1)
		ans.append(s0)
		ans.append(s0)
		ans.append(s1)
	if r1 > 0:
		ans.append(s1)
		ans.append(s0)
	for j in ans:
		lst = list(j)
		print(*lst)


def Thing(x):
	return x % 4 in [0, 3]
for qwer in range(int(input())):
	aaa = [int(lskadng) for lskadng in input().split()]
	for i in range(aaa[0]):
		lol = ''
		for j in range(aaa[1]):
			lol += str((Thing(i) + Thing(j)) % 2)
			if j != aaa[1] - 1:
				lol += ' '
		print(lol)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [0] * m
	flag = False
	c = 0
	for i in range(m):
		if i % 4 == 0 or i % 4 == 3:
			a[i] = 1
	b = [0] * m
	for i in range(m):
		if a[i] == 0:
			b[i] = 1
		else:
			b[i] = 0
	for j in range(n):
		if j % 4 == 0 or j % 4 == 3:
			print(*a)
		else:
			print(*b)


t = int(input())
for _ in range(0, t):
	inputs = [int(num) for num in input().split()]
	n = inputs[0]
	m = inputs[1]
	row1 = [1]
	k = 0
	for i in range(0, (m - 2) // 2):
		if i % 2 == 0:
			row1.append(0)
			row1.append(0)
			k = 1
		else:
			row1.append(1)
			row1.append(1)
			k = 0
	if k == 0:
		row1.append(0)
	else:
		row1.append(1)
	row2 = [0]
	k = 0
	for i in range(0, (m - 2) // 2):
		if i % 2 == 0:
			row2.append(1)
			row2.append(1)
			k = 1
		else:
			row2.append(0)
			row2.append(0)
			k = 0
	if k == 0:
		row2.append(1)
	else:
		row2.append(0)
	print(*row1)
	k = 0
	for i in range(0, (n - 2) // 2):
		if i % 2 == 0:
			print(*row2)
			print(*row2)
			k = 1
		else:
			print(*row1)
			print(*row1)
			k = 0
	if k == 0:
		print(*row2)
	else:
		print(*row1)


tc = int(input())
for i in range(tc):
	(nt, mt) = map(int, input().split())
	op = []
	str_a = '10'
	str_b = '01'
	str_1 = ''
	str_2 = ''
	for j in range(mt // 2):
		if j % 2 != 0:
			str_2 += str_a
			str_1 += str_b
		else:
			str_1 += str_a
			str_2 += str_b
	for g in range(nt):
		if g % 4 == 0 or g % 4 == 3:
			op.append(list(str_1))
		else:
			op.append(list(str_2))
	for h in range(len(op)):
		print(*op[h])


for s in [*open(0)][1:]:
	(n, m) = map(int, s.split())
	for r in (([([0, 0, 1, 1] * m)[1:m + 1]] * 2 + [([1, 1, 0, 0] * m)[1:m + 1]] * 2) * n)[1:n + 1]:
		print(*r)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	output_arr = []
	a = '10'
	b = '01'
	string = ''
	string2 = ''
	for i in range(k // 2):
		if i % 2 == 0:
			string += a
			string2 += b
		else:
			string += b
			string2 += a
	for i in range(n):
		if i % 4 == 0 or i % 4 == 3:
			output_arr.append(list(string))
		else:
			output_arr.append(list(string2))
	for i in range(len(output_arr)):
		print(*output_arr[i])


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	L = [1]
	M = [0]
	for i in range(1, m):
		if i % 4 == 1 or i % 4 == 2:
			L.append(0)
			M.append(1)
		else:
			L.append(1)
			M.append(0)
	for i in range(n):
		if i % 4 == 0 or i % 4 == 3:
			print(*L)
		else:
			print(*M)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	row = [0] * m
	for i in range(m):
		if i % 4 == 0 or i % 4 == 3:
			row[i] = 1
	row2 = [int(not i) for i in row]
	for i in range(n):
		if i % 4 == 0 or i % 4 == 3:
			print(*row)
		else:
			print(*row2)


first = [0, 1, 1, 0] * 15
second = [1, 0, 0, 1] * 15
final = [first, second, second, first] * 15
for _ in range(int(input())):
	(row, col) = map(int, input().split())
	for i in range(row):
		print(*final[i][:col])


def ss(n, m):
	lst = []
	a = [1, 0, 0, 1] * (m // 4) + [1, 0] * (m % 4 - 1)
	b = [0, 1, 1, 0] * (m // 4) + [0, 1] * (m % 4 - 1)
	for i in range(n // 2):
		if i % 2 == 0:
			lst.append(a)
			lst.append(b)
		else:
			lst.append(b)
			lst.append(a)
	return lst
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lst = ss(n, m)
	for i in lst:
		print(*i)


def solve():
	(n, m) = map(int, input().split())
	res = ['' for _ in range(n)]
	m //= 2
	n //= 2
	b = True
	for i in range(n):
		for j in range(m):
			if b:
				res[i * 2] += '10'
				res[i * 2 + 1] += '01'
			else:
				res[i * 2] += '01'
				res[i * 2 + 1] += '10'
			b = not b
		if res[i * 2][0] == '1':
			b = False
		else:
			b = True
	for i in res:
		print(*list(i))
	return

def main():
	for _ in range(int(input())):
		solve()
	return
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n == 2 and m == 2:
		print(1, 0)
		print(0, 1)
		continue
	a = []
	b = [1, 0]
	c = [0, 1]
	t = 1
	d = []
	for j in range(m // 2):
		if t == 1:
			d += b
		else:
			d += c
		t = t ^ 1
	a += [d]
	for i in range(1, n):
		if i % 2 == 1:
			t = a[i - 1][0] ^ 1
		elif i % 2 == 0:
			t = a[i - 1][0]
		d = []
		for j in range(m // 2):
			if t == 1:
				d += b
			else:
				d += c
			t = t ^ 1
		a += [d]
	for i in a:
		print(*i)


for _ in range(int(input())):
	(n, m) = [int(y) for y in input().split()]
	chng = 1
	inp = 1
	tmp1 = []
	tmp2 = []
	for i in range(m):
		if chng == 2:
			inp ^= 1
			chng = 0
		tmp1.append(inp)
		tmp2.append(inp ^ 1)
		chng += 1
	flag = True
	a = []
	for i in range(int(n // 2)):
		if flag:
			a.append(tmp1)
			a.append(tmp2)
			flag = False
		else:
			a.append(tmp2)
			a.append(tmp1)
			flag = True
	for i in range(n):
		print(*a[i])


for _ in range(int(input())):
	a = [1, 0, 0, 1] * 13
	b = [0, 1, 1, 0] * 13
	(m, n) = list(map(int, input().split()))
	for i in range(m):
		if i % 4 == 0:
			print(*b[:n])
		elif i % 4 == 1:
			print(*a[:n])
		elif i % 4 == 2:
			print(*a[:n])
		elif i % 4 == 3:
			print(*b[:n])


test = int(input())
while test:
	(n, m) = map(int, input().split())
	row = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]
	order = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]
	same = row[:m]
	rev = []
	for i in same:
		if i == 0:
			rev.append(1)
		else:
			rev.append(0)
	print(*same)
	for i in range(n - 2):
		if order[i]:
			print(*same)
		else:
			print(*rev)
	if n // 2 % 2 == 0:
		print(*same)
	else:
		print(*rev)
	test -= 1


def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		field = [[0] * m for _ in range(n)]
		for i in range(n):
			for j in range(m):
				if i % 4 == 0 or i % 4 == 3:
					if j % 4 == 1 or j % 4 == 2:
						field[i][j] = 1
				elif j % 4 == 0 or j % 4 == 3:
					field[i][j] = 1
		for f in field:
			print(*f)
main()


def solve(n, m):
	l = [[0] * m for k in range(n)]
	for i in range(n):
		if (i + 1) % 4 == 0 or (i + 1) % 4 == 1:
			for j in range(m):
				if (j + 1) % 4 == 0 or (j + 1) % 4 == 1:
					l[i][j] = 1
				else:
					l[i][j] = 0
		else:
			for j in range(m):
				if (j + 1) % 4 == 0 or (j + 1) % 4 == 1:
					l[i][j] = 0
				else:
					l[i][j] = 1
	return l
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	final = solve(n, m)
	for i in final:
		print(*i)


def soln():
	(x, y) = map(int, input().split())
	ans = []
	l1 = [1, 0, 0, 1]
	l2 = [0, 1, 1, 0]
	if y % 4 == 2:
		val1 = [1, 0, 0, 1] * (y // 4) + l1[:2]
		val2 = [0, 1, 1, 0] * (y // 4) + l2[:2]
	else:
		val1 = [1, 0, 0, 1] * (y // 4)
		val2 = [0, 1, 1, 0] * (y // 4)
	ans = []
	cnt = 1
	for i in range(x // 2):
		if cnt == 1:
			ans.append(val1)
			ans.append(val2)
			cnt = 0
		else:
			ans.append(val2)
			ans.append(val1)
			cnt = 1
	for i in ans:
		print(*i)
t = int(input())
for _ in range(0, t):
	soln()


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	ans = [[], []]
	flag = 0
	for i in range(m // 2):
		if flag == 0:
			ans[0].append(1)
			ans[0].append(0)
			flag = 1
		else:
			ans[0].append(0)
			ans[0].append(1)
			flag = 0
	flag = 0
	for i in range(m // 2):
		if flag == 1:
			ans[1].append(1)
			ans[1].append(0)
			flag = 0
		else:
			ans[1].append(0)
			ans[1].append(1)
			flag = 1
	p = []
	flag = 0
	for i in range(n // 2):
		if flag == 0:
			p.append(ans[0])
			p.append(ans[1])
			flag = 1
		else:
			p.append(ans[1])
			p.append(ans[0])
			flag = 0
	for i in range(n):
		print(*p[i])


for s in [*open(0)][1:]:
	(n, m) = map(int, s.split())
	print(*((i ^ j) % 4 // 2 for i in range(1, n + 1) for j in range(1, m + 1)))