def struct(n: int) -> list:
aim = n * (n + 1) // 4 - n
seq = []
for i in range(n, 1, -1):
while aim >= i * (i - 1) // 2:
if len(seq) == 0:
add = [0] * i
else:
add = [seq[-1] ^ 1] * i
seq.extend(add)
aim -= i * (i - 1) // 2
leave = n - len(seq)
if leave == n:
leave -= 1
seq.append(0)
for _ in range(leave):
seq.append(seq[-1] ^ 1)
return seq
T = int(input())
for _ in range(T):
n, m = map(int, input().split())
ans = []
if n * (n + 1) // 2 % 2 and m * (m + 1) // 2 % 2:
print("No")
continue
elif m * (m + 1) // 2 % 2:
seq = struct(n)
for i in range(n):
ans.append([seq[i]] * m)
else:
seq = struct(m)
for _ in range(n):
ans.append(seq)
print("Yes")
for i in range(n):
print(*ans[i])