You are given four positive integers $n$, $m$, $a$, $b$ ($1 \le b \le n \le 50$; $1 \le a \le m \le 50$). Find any such rectangular matrix of size $n \times m$ that satisfies all of the following conditions:

  each row of the matrix contains exactly $a$ ones;  each column of the matrix contains exactly $b$ ones;  all other elements are zeros. 

If the desired matrix does not exist, indicate this.

For example, for $n=3$, $m=6$, $a=2$, $b=1$, there exists a matrix satisfying the conditions above:

$$ \begin{vmatrix} 0 & 1 & 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 0 \end{vmatrix} $$


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.

Each test case is described by four positive integers $n$, $m$, $a$, $b$ ($1 \le b \le n \le 50$; $1 \le a \le m \le 50$), where $n$ and $m$ are the sizes of the matrix, and $a$ and $b$ are the number of ones for rows and columns, respectively.


-----Output-----

For each test case print:

  "YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or  "NO" (without quotes) if it does not exist. 

To print the matrix $n \times m$, print $n$ rows, each of which consists of $m$ numbers $0$ or $1$ describing a row of the matrix. Numbers must be printed without spaces.


-----Example-----
Input
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2

Output
YES
010001
100100
001010
NO
YES
11
11
YES
1100
1100
0011
0011
YES
1
1

Source: codeforces | Difficulty: HARD
Tags: Greedy algorithms

Mathematics

Constructive algorithms


Solutions:
T = int(input())
for t_itr in range(T):
	(N, M, A, B) = map(int, input().rstrip().split())
	result = [['0' for _ in range(M)] for _ in range(N)]
	if M * B != N * A:
		print('No')
	else:
		for i in range(N):
			for j in range(i * A, A + i * A):
				result[i][j % M] = '1'
		print('Yes')
		for r in result:
			print(''.join(r))


import math
t = int(input())
for p in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	else:
		print('YES')
		ans = ['0' * m for i in range(n)]
		h = a % m
		k = 0
		for i in range(n):
			if k + a <= m:
				u = ans[i][:k] + '1' * a + ans[i][k + a:]
			else:
				u = '1' * (k + a - m) + ans[i][k + a - m:k] + '1' * (m - k)
			k += h
			k = k % m
			print(u)


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	l = [[0 for j in range(m)] for i in range(n)]
	if n / m == b / a:
		(i, j) = (0, 0)
		for k in range(0, n):
			for z in range(0, a):
				l[i][j] = 1
				j = (j + 1) % m
			i = (i + 1) % n
		print('YES')
		for i in range(0, n):
			for j in range(0, m):
				print(l[i][j], end='')
			print()
	else:
		print('NO')


import io
import os
from collections import Counter, defaultdict, deque

def solve(R, C, A, B):
	if R * A != C * B:
		return 'NO'
	grid = [[0 for c in range(C)] for r in range(R)]
	for r in range(R):
		for i in range(A):
			grid[r][(r * A + i) % C] = 1
	return 'YES\n' + '\n'.join((''.join(map(str, row)) for row in grid))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, M, A, B) = [int(x) for x in input().split()]
	ans = solve(N, M, A, B)
	print(ans)


import sys
from collections import defaultdict as dd

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
import copy
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

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

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

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

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

def bo(i):
	return ord(i) - ord('a')
import copy
t = fi()
while t > 0:
	t -= 1
	(n, m, a, b) = mi()
	d = [['0' for i in range(m)] for j in range(n)]
	i = 0
	j = 0
	flag = 0
	for k in range(b * m):
		if d[i][j] == '1':
			pp = i - 1
			while i != pp - 1 and d[i][j] == '1':
				i += 1
				i %= n
				if d[i][j] == '0':
					d[i][j] = '1'
					f = 1
					break
			i = (i + 1) % n
			j = (j + 1) % m
			if f == 0:
				flag = 1
				break
		else:
			d[i][j] = '1'
			i = (i + 1) % n
			j = (j + 1) % m
	if flag:
		print('NO')
		continue
	for i in range(n):
		v = 0
		for j in range(m):
			if d[i][j] == '1':
				v += 1
		if v != a:
			flag = 1
			break
	if flag:
		print('NO')
		continue
	print('YES')
	for i in d:
		print(''.join(i))


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	t = '1' * a + '0' * (m - a)
	for i in range(n):
		print(t)
		t = t[m - a:] + t[:m - a]


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

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

def slv(N, M, A, B):
	if N * A != M * B:
		print('NO')
		return
	print('YES')
	mat = [[0] * M for _ in range(N)]
	for i in range(N):
		for j in range(A):
			mat[i][(i * A + j) % M] = 1
	for r in mat:
		print(''.join(map(str, r)))

def main():
	T = read_int()
	for _ in range(T):
		(N, M, A, B) = read_int_n()
		slv(N, M, A, B)
main()


def solve():
	(n, m, a, b) = [int(x) for x in input().split()]
	if a * n != b * m:
		print('NO')
		return
	else:
		print('YES')
		col_sum = [[0, i] for i in range(m)]
		for i in range(n):
			col_sum.sort()
			s = ['0'] * m
			for i in range(a):
				if col_sum[i][0] < b:
					s[col_sum[i][1]] = '1'
					col_sum[i][0] += 1
			print(''.join(s))
t = int(input())
for i in range(t):
	solve()


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

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

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

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

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

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
for _ in range(iinput()):
	(n, m, a, b) = rinput()
	if n * a == m * b:
		print('YES')
		for i in range(n):
			add = '1' * a + '0' * (m - a)
			idx = a * i % m
			print(add[idx:] + add[:idx])
	else:
		print('NO')


def solve():
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		return
	else:
		print('YES')
		for i in range(n):
			row = ['0' for j in range(m)]
			for j in range(i * a, a * (i + 1)):
				row[j % m] = '1'
			print(''.join(row))
		return
t = int(input())
for case in range(t):
	solve()


import math
t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('No')
		continue
	else:
		gcdnm = math.gcd(n, m)
		ans = []
		for i in range(n):
			ans.append([])
			for j in range(m):
				if (i + j * n // gcdnm) % n < b:
					ans[i].append('1')
				else:
					ans[i].append('0')
		print('Yes')
		for line in ans:
			print(''.join(line))


t = int(input())
for i in range(t):
	nmab = list(map(int, input().strip().split()))
	n = nmab[0]
	m = nmab[1]
	a = nmab[2]
	b = nmab[3]
	if n * a != m * b or m * n == 0:
		print('NO')
	else:
		arr = [[0 for i in range(m)] for j in range(n)]
		i = 0
		s = 0
		while i < n:
			for l in range(0, a):
				arr[i][(s + l) % m] = 1
			s = (s + a) % m
			i += 1
		print('YES')
		for i in range(n):
			p = ''
			for j in arr[i]:
				p += str(j)
			print(p)


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

def read_ints():
	return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
	(n, m, a, b) = read_ints()
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		ans = [[0 for i in range(m)] for j in range(n)]
		row = 0
		col = 0
		t = 0
		while True:
			ans[row][col] = 1
			t += 1
			if t == n * a:
				break
			col = (col + 1) % m
			row = (row + 1) % n
			while ans[row][col] == 1:
				col = (col + 1) % m
		for i in range(n):
			print(''.join(map(str, ans[i])))


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		j = 0
		for i in range(n):
			k = ['0'] * m
			for r in range(a):
				k[(j + r) % m] = '1'
			j += a
			j %= m
			print(''.join(k))


def main():
	t = int(input())
	for _test_case in range(t):
		(n, m, a, b) = map(int, input().split())
		if n * a != m * b:
			print('NO')
		elif n * a % m != 0:
			print('NO')
		elif m * b % n != 0:
			print('NO')
		else:
			print('YES')
			i = 0
			for _row in range(n):
				line = [0] * m
				for _ in range(a):
					line[i] = 1
					i = (i + 1) % m
				print(''.join([str(i) for i in line]))
main()


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, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		l = [['0'] * m for j in range(n)]
		c = 0
		if a <= b:
			for j in range(n):
				for k in range(c, c + a):
					l[j][k % m] = '1'
				c = (c + a) % m
			for j in l:
				print(''.join(j))
		else:
			for j in range(m):
				for k in range(c, c + b):
					l[k % n][j] = '1'
				c = (c + b) % n
			for j in l:
				print(''.join(j))


import sys, math
from collections import defaultdict as dd
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, m, a, b) = inp()
	if n * a != m * b:
		print('NO')
		continue
	ans = [[0 for i in range(m)] for j in range(n)]
	c = 0
	for i in range(n):
		for j in range(a):
			if c == m:
				c = 0
			ans[i][c] = 1
			c += 1
	print('YES')
	for i in ans:
		print(*i, sep='')


import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
from math import radians, cos, sin, tan, ceil, floor, log, factorial, gcd, pi

def main():
	T = int(input())
	for _ in range(T):
		(N, M, A, B) = map(int, input().split())
		if M * B != N * A:
			print('NO')
			continue
		ans = [[0] * M for _ in range(N)]
		x = gcd(N, B)
		y = gcd(M, A)
		for i in range(N):
			s = i // x * y
			for j in range(s, s + A):
				ans[i][j % M] = 1
		print('YES')
		print('\n'.join([''.join(map(str, a)) for a in ans]))
main()


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	d = 1
	while d * n % m != 0 and d < m:
		d += 1
	s = '1' * a + '0' * (m - a)
	for _ in range(n):
		print(s)
		s = s[-d:] + s[:-d]


t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('no')
		continue
	print('YES')
	ans = ['1' for i in range(a)] + ['0' for i in range(m - a)]
	for i in range(n):
		for j in range(m):
			print(ans[(a * i + j - 1) % m], end='')
		print()


for i in range(int(input())):
	(n, m, a, b) = list(map(int, input().split()))
	c = [[0 for i in range(m)] for j in range(n)]
	j = 0
	for i in range(n):
		for k in range(a):
			c[i][j] = 1
			j = (j + 1) % m
	for i in range(m):
		d = 0
		for j in range(n):
			d += c[j][i]
		if d != b:
			print('NO')
			break
	else:
		print('YES')
		for i in c:
			print(*i, sep='')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	mtrx = []
	for i in range(n):
		r = ['0' for _ in range(m)]
		for j in range(a):
			r[(i * a + j) % m] = '1'
		mtrx.append(r)
	c = True
	for i in range(m):
		s = 0
		for j in range(n):
			s += int(mtrx[j][i] == '1')
		if s != b:
			c = False
			break
	if not c:
		print('NO')
		continue
	print('YES')
	for r in mtrx:
		print(''.join(r))


def calc(n, m, a, b):
	if n * a != m * b:
		return -1
	res = [[0 for i in range(m)] for j in range(n)]
	if n == m:
		for i in range(n):
			for j in range(i, i + a):
				res[i][j % m] = 1
	if n > m:
		for i in range(m):
			for j in range(i, i + a):
				res[i][j % m] = 1
		tg = calc(n - m, m, a, (n - m) * a // m)
		if tg == -1:
			return -1
		for i in range(m, n):
			for j in range(m):
				res[i][j] = tg[i - m][j]
	if n < m:
		tg = calc(m, n, b, a)
		if tg == -1:
			return -1
		for i in range(n):
			for j in range(m):
				res[i][j] = tg[j][i]
	return res
t = int(input())
for i in range(t):
	(n, m, a, b) = [int(i) for i in input().split()]
	res = calc(n, m, a, b)
	if res == -1:
		print('NO')
	else:
		print('YES')
		for i in res:
			st = ''
			for j in i:
				st += str(j)
			print(st)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

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

def inv_mod(n):
	return pow(n, mod - 2, mod)

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

def st():
	return str(input().rstrip())[2:-1]

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

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]

def satisy(n, m, a, b, l):
	for i in l:
		if sum(i) != a:
			return 0
	for j in range(m):
		curr = 0
		for i in range(n):
			curr += l[i][j]
		if curr != b:
			return 0
	return 1
for _ in range(val()):
	(n, m, a, b) = li()
	l = [[0] * m for i in range(n)]
	col = 0
	for i in range(n):
		for j in range(col, col + a):
			l[i][j % m] = 1
		col += m - a
	if satisy(n, m, a, b, l):
		print('YES')
		for i in l:
			print(*i, sep='')
	else:
		print('NO')


t = int(input())
for tes in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	ans = [[0 for i in range(m)] for i in range(n)]
	if a <= b:
		for i in range(n):
			for j in range(a):
				ans[i][(a * i + j) % m] = 1
	else:
		for x in range(m):
			for y in range(b):
				ans[(b * x + y) % n][x] = 1
	for i in range(n):
		s = ''
		for j in range(m):
			s += str(ans[i][j])
		print(s)


import sys

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

def main():
	for _ in range(int(input())):
		(n, m, a, b) = map(int, input().split())
		if abs(n / b - m / a) > 1e-05:
			print('NO')
		else:
			print('YES')
			ans = [['0'] * m for k in range(n)]
			for k in range(n):
				for l in range(k * a, k * a + a):
					ans[k][l % m] = '1'
			for e in ans:
				print(''.join(e))
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(r, c, a, b) = map(int, input().split())
	if r * a != c * b:
		print('NO')
		continue
	colarr = [b for i in range(c)]
	rowarr = [a for i in range(r)]
	grid = [[0 for i in range(c)] for j in range(r)]
	for i in range(r):
		for j in range(c):
			mini = 0
			minpos = -1
			for k in range(c):
				if colarr[k] > mini:
					mini = colarr[k]
					minpos = k
			if rowarr[i] > 0 and colarr[minpos] > 0:
				grid[i][minpos] = 1
				colarr[minpos] -= 1
				rowarr[i] -= 1
	f = 0
	for i in range(c):
		if colarr[i] > 0:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		for j in range(r):
			if rowarr[j] > 0:
				f = 1
				break
		if f == 0:
			print('YES')
			for i in grid:
				for j in i:
					sys.stdout.write(str(j))
				sys.stdout.write('\n')
		else:
			print('NO')


from sys import stdin, exit, setrecursionlimit
from collections import deque
from heapq import _heappop_max, heappush, heappop
from math import gcd
from math import ceil, log2
setrecursionlimit(10000000)
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()

def valid():
	for i in grid:
		if i.count(1) != a:
			return False
	for i in range(m):
		cnt = 0
		for j in range(n):
			cnt += grid[j][i]
		if cnt != b:
			return False
	return True
for _ in range(int(input())):
	(n, m, a, b) = mi()
	grid = [[0 for i in range(m)] for j in range(n)]
	idx = 0
	for i in range(n):
		for j in range(a):
			grid[i][idx % m] = 1
			idx += 1
	if valid():
		print('YES')
		for i in grid:
			print(''.join([str(j) for j in i]))
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	c = []
	for i in range(n):
		c.append([])
		for j in range(m):
			c[i].append(0)
	d = 0
	for i in range(n):
		for j in range(a):
			c[i][d % m] = 1
			d += 1
	for x in c:
		print(*x, sep='')


t = int(input())
for i in range(t):
	(n, k, a, b) = map(int, input().split())
	if n * a == k * b:
		print('YES')
		ans = ['' for j in range(n)]
		ans[0] = '1' * a + (k - a) * '0'
		for i in range(1, n):
			ans[i] = ans[i - 1][k - a:] + ans[i - 1][:k - a]
		for i in ans:
			print(''.join(map(str, i)))
	else:
		print('NO')


for nt in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	if a == m:
		ans = [['1' for i in range(m)] for j in range(n)]
		for i in ans:
			for j in i:
				print(j, end='')
			print()
		continue
	ans = ['1' * a + '0' * (m - a)]
	for i in range(n - 1):
		ans.append(ans[-1][m - a:] + ans[-1][0:m - a])
	for i in ans:
		for j in i:
			print(j, end='')
		print()


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

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

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

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

def binaryToDecimal(n):
	return int(n, 2)

def solve():
	(n, m, a, b) = num_input()
	if n / m == b / a:
		print('YES')
		end = 0
		t = '1' * a + '0' * (m - a)
		for i in range(n):
			print(t)
			t = t[m - a:] + t[:m - a]
	else:
		print('NO')
t = int(input())
for _ in range(t):
	solve()


def main():
	(n, m, a, b) = map(int, input().split())
	if a * n != b * m or a > m:
		print('NO')
		return
	else:
		print('YES')
	grid = [['0'] * m for _ in range(n)]
	cnt = 0
	delta = 0
	i = 0
	while cnt < a * n:
		while grid[(i + delta) % n][i % m] == '1':
			delta += 1
		grid[(i + delta) % n][i % m] = '1'
		cnt += 1
		i += 1
	for line in grid:
		print(''.join(line))
tn = int(input())
for _ in range(tn):
	main()


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, m, a, b) = map(int, stdin.readline().split())
	if n * a != m * b:
		print('NO')
		continue
	shift = 0
	for i in range(1, m):
		if i * n % m == 0:
			shift = i
			break
	board = [[0] * m for _ in range(n)]
	for i in range(n):
		for k in range(a):
			board[i][(i * shift + k) % m] = 1
	print('YES')
	for row in board:
		print(''.join(map(str, row)))


t = int(input())
for _ in range(t):
	(n, m, a, b) = [int(x) for x in input().split()]
	if n * a != m * b:
		print('NO')
		continue
	l = []
	ans = [[0 for i in range(m)] for j in range(n)]
	for i in range(m):
		l.append([0, i])
	l.sort()
	for i in range(n):
		for j in range(a):
			x = l[j][1]
			ans[i][x] = 1
			l[j][0] += 1
		l.sort()
	print('YES')
	for i in ans:
		a = ''
		for j in i:
			a += str(j)
		print(a)


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

def solve():
	(n, m, a, b) = [int(x) for x in input().split()]
	if n * a != m * b:
		print('NO')
		return
	d = deque()
	for i in range(a):
		d.append('1')
	for i in range(m - a):
		d.append('0')
	print('YES')
	for i in range(n):
		print(''.join(d))
		d.rotate(a)
tt = int(input())
for test in range(tt):
	solve()


import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(val + '\n')

def prog():
	for _ in range(int(input())):
		(n, m, a, b) = map(int, input().split())
		if n * a == m * b:
			print('YES')
			string = '1' * a + '0' * (m - a)
			for i in range(n):
				print(string)
				string = string[m - a:] + string[:m - a]
		else:
			print('NO')
prog()


T = int(input())
for t in range(T):
	(n, m, a, b) = list(map(int, input().split()))
	if n * a != m * b:
		res = 'NO'
	else:
		matrix = [['0' for j in range(m)] for i in range(n)]
		res = 'YES'
		steps = 0
		max_steps = n * a
		cur_col = 0
		cur_row = 0
		while steps < max_steps:
			matrix[cur_row][cur_col] = '1'
			cur_col += 1
			if cur_col == m:
				cur_col = 0
			steps += 1
			if steps % a == 0:
				cur_row += 1
	print(res)
	if res == 'YES':
		for i in range(n):
			print(''.join(matrix[i]))


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 6)
	T = int(input())
	for t in range(T):
		(n, m, a, b) = [int(x) for x in input().strip().split()]
		if n * a != m * b:
			print('NO')
			continue
		print('YES')
		l = '1' * a + '0' * (m - a)
		for ni in range(n):
			print(l)
			l = l[-a:] + l[:m - a]
main()


t = int(input())

def solve():
	mat = [[0 for j in range(m)] for i in range(n)]
	for i in range(n):
		for j in range(a):
			mat[i][(i * a + j) % m] = 1
	return mat
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a == m * b:
		mat = solve()
		print('YES')
		for i in range(n):
			print(*mat[i], sep='')
	else:
		print('NO')


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

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

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

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

def solve():
	(n, m, a, b) = map(int, input().strip().split())
	matrix = [[0 for _ in range(m)] for _ in range(n)]
	if n * a != m * b:
		print('NO')
	else:
		ans = 'YES'
		j = 0
		for i in range(n):
			(tempb, tempa) = (b, a)
			f = 0
			while tempa > 0 and f != 2:
				matrix[i][j] = 1
				tempa -= 1
				j = (j + 1) % m
				if j == i % m:
					f += 1
		print(ans)
		if ans == 'YES':
			for i in range(n):
				print(''.join((str(e) for e in matrix[i])))

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

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

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

def solve():
	(n, m, a, b) = rl()
	if n * a != b * m:
		print('NO')
		return
	matrix = []
	for i in range(n):
		matrix.append([0] * m)
	rowsum = 0
	for init_row in range(50):
		col = 0
		row = init_row
		for i in range(n * a):
			matrix[row][col] = 1
			if row == 0:
				rowsum += 1
			row = (row + 1) % n
			col = (col + 1) % m
			if (row, col) == (init_row, 0):
				break
		if rowsum == a:
			break
	print('YES')
	for i in range(n):
		for j in range(m):
			print(matrix[i][j], end='')
		print()
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


def scanInt():
	return int(input())

def scanList():
	return [i for i in input().split(' ')]

def scanIntList():
	return [int(i) for i in scanList()]
t = scanInt()

def solve(string, count):
	return string[-count:] + string[:-count]
for _ in range(t):
	(n, m, a, b) = map(int, input().split(' '))
	if n * a == m * b:
		print('YES')
		s = ['1' for i in range(a)] + ['0' for i in range(m - a)]
		for i in range(n):
			for j in s:
				print(j, end='')
			print()
			s = solve(s, a)
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if b * m != a * n:
		print('NO')
		continue
	ans = [['1'] * m for i in range(n)]
	curr_row = [m] * n
	curr_col = [n] * m
	row = 0
	col = 0
	while col < m:
		while curr_col[col] > b:
			if curr_row[row] > a:
				ans[row][col] = '0'
				curr_row[row] -= 1
				curr_col[col] -= 1
				row = (row + 1) % n
		col += 1
	print('YES')
	s = ''
	for e in ans:
		for ee in e:
			s += ee
		s += '\n'
	print(s)


t = int(input())
for i in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a == m * b:
		arr = [[0 for k in range(m)] for j in range(n)]
		k = 0
		q = 0
		for j in range(n):
			c = 0
			k = q
			while c < a:
				arr[j][k] = 1
				c = c + 1
				k = (k + 1) % m
			q = (q + a) % m
		print('YES')
		for j in range(n):
			print(''.join(map(str, arr[j])))
	else:
		print('NO')


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

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])
for _ in range(int(input())):
	(n, m, a, b) = ilele()
	A = ['0'] * m
	Ans = []
	for i in range(n):
		Ans.append(A.copy())
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		freq = []
		for i in range(m):
			freq.append([0, i])
		for i in range(n):
			E = list(sorted(freq))
			p = 0
			for (j, k) in E:
				p += 1
				Ans[i][k] = '1'
				freq[k] = [j + 1, k]
				if p >= a:
					break
		for i in Ans:
			x = ''.join(i)
			print(x)


import math
T = int(input())

def possible(n, m, a, b):
	if not n * a == m * b:
		return False
	ans = []
	for i in range(n):
		ans += [['0'] * m]
	for t in range(n):
		x0 = t
		y0 = t * a % m
		for y in range(a):
			ans[x0][(y0 + y) % m] = '1'
	return ans

def ans(n, m, a, b):
	x = possible(n, m, a, b)
	if x:
		print('YES')
		for row in x:
			print(''.join(row))
		return
	print('NO')
for t in range(T):
	(n, m, a, b) = input().split(' ')
	(n, m, a, b) = (int(n), int(m), int(a), int(b))
	ans(n, m, a, b)


import sys
from math import gcd
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, m, a, b) = I()
	f = 0
	s = ['1'] * a
	if a * n == b * m:
		an = [['0'] * m for i in range(n)]
		x = 0
		print('YES')
		d = 0
		for i in range(1, m):
			if i * n % m == 0:
				d = i
				break
		for i in range(n):
			for j in range(x, x + a):
				an[i][j % m] = '1'
			x += d
		if f == 0:
			for i in an:
				print(''.join(i))
	else:
		print('NO')


t = int(input())
from heapq import heappush as pu
from heapq import heappop as po
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	q = []
	for i in range(m):
		pu(q, (-b, i))
	ma = [[0 for i in range(m)] for i in range(n)]
	tt = True
	for i in range(n):
		s = []
		for j in range(a):
			(x, k) = po(q)
			x = -x
			ma[i][k] = 1
			s.append((-x + 1, k))
		for (x, k) in s:
			pu(q, (x, k))
	for i in range(n):
		if ma[i].count(1) != a:
			tt = False
	for j in range(m):
		c = 0
		for i in range(n):
			c += ma[i][j]
		if c != b:
			tt = False
	if tt:
		print('YES')
		for i in range(n):
			print(''.join([str(i) for i in ma[i]]))
	else:
		print('NO')


from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect
import math
import heapq
import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for ii in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	ans = [[0] * m for i in range(n)]
	if a * n != m * b:
		print('NO')
		continue
	ind = 0
	for i in range(n):
		for j in range(a):
			ans[i][ind] = 1
			ind += 1
			ind = ind % m
	print('YES')
	for i in range(n):
		for j in range(m):
			print(ans[i][j], end='')
		print()


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		mat = [[0 for j in range(m)] for i in range(n)]
		st = 0
		for i in range(n):
			for j in range(st, st + a):
				mat[i][j % m] = 1
			st = j + 1
		for i in range(n):
			for j in range(m):
				print(mat[i][j], end='')
			print()


t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a == m * b:
		print('YES')
		L = [['0' for i in range(m)] for j in range(n)]
		x = m * b
		(r, c) = (0, 0)
		(ss, st) = (0, 0)
		for i in range(x):
			L[r][c] = '1'
			r += 1
			c += 1
			r %= n
			c %= m
			if r == ss and c == st:
				if n <= m:
					st += 1
					c += 1
					c %= m
				else:
					ss += 1
					r += 1
					r %= n
		for i in range(n):
			for j in range(m):
				print(L[i][j], end='')
			print()
	else:
		print('NO')


from collections import defaultdict as dd
import math

def nn():
	return int(input())

def li():
	return list(input())

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

def lm():
	return list(map(int, input().split()))
q = nn()
for _ in range(q):
	(n, m, a, b) = mi()
	if not m * b == n * a:
		print('NO')
		continue
	print('YES')
	for i in range(n):
		row = []
		for j in range(m):
			if (a * i + j) % m < a:
				row.append('1')
			else:
				row.append('0')
		print(''.join(row))


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	mat = []
	if a * n != b * m:
		print('NO')
		continue
	print('YES')
	mat.append([1] * a + [0] * (m - a))
	for i in range(1, n):
		ind = a * i % m
		curr = [0] * m
		curr[ind:min(m, ind + a)] = [1] * min(a, m - ind)
		if curr.count(1) != a:
			curr[:a - curr.count(1)] = [1] * (a - curr.count(1))
		mat.append(curr)
	for i in mat:
		print(*i, sep='')


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, m, a, b) = map(int, input().split())
	if a * n != m * b:
		print('NO')
		continue
	ANS = [[0] * m for i in range(n)]
	cind = 0
	for i in range(n):
		for j in range(a):
			ANS[i][cind] = 1
			cind += 1
			cind %= m
	print('YES')
	for a in ANS:
		print(''.join(map(str, a)))


def gnrtmat(row, col):
	return [[0 for j in range(col)] for i in range(row)]
for t in range(int(input())):
	(n, m, a, b) = [int(x) for x in input().split(' ')]
	if n * a != m * b:
		print('NO')
	else:
		mat = gnrtmat(n, m)
		for j in range(m):
			for i in range(b):
				mat[i][j] = 1
		for i in range(n):
			row = mat[i]
			s = sum(mat[i])
			col = 0
			while s > a:
				mat[i][col] = 0
				rowt = i + 1
				rowoverflow = False
				while mat[rowt][col] != 0:
					rowt += 1
					if rowt == n:
						rowoverflow = True
						break
				if rowoverflow:
					mat[i][col] = 1
					col += 1
					continue
				mat[rowt][col] = 1
				col += 1
				s -= 1
		print('YES')
		for row in mat:
			print(*row, sep='')


import sys
inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
ttt = int(inp[ii])
ii += 1
res = []
for _ in range(ttt):
	(n, m, a, b) = inp[ii:ii + 4]
	ii += 4
	if n * a == m * b:
		res.append('YES')
		for i in range(n):
			c = [0] * m
			for j in range(a):
				c[(i * a + j) % m] = 1
			res.append(''.join((str(x) for x in c)))
	else:
		res.append('NO')
print('\n'.join((str(x) for x in res)))


from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)
mod = 1000000007
inf = int(1e+18)
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

def inverse(a):
	return pow(a, mod - 2, mod)

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

def solve():
	(n, m, a, b) = map(int, input().split())
	if a * n != b * m:
		print('NO')
		return
	print('YES')
	s = []
	for d in range(1, m + 1):
		if d * n % m > 0:
			continue
		c = ['1'] * a + ['0'] * (m - a)
		for i in range(n):
			s.append(c)
			c = c[d:] + c[:d]
		break
	for x in s:
		print(''.join(x))

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


t = input()
for tt in range(int(t)):
	(n, m, a, b) = map(int, input().split())
	if n * a == m * b:
		print('YES')
		for i in range(n):
			s = ['0'] * m
			for j in range(a):
				s[(i * a + j) % m] = '1'
			print(''.join(s))
	else:
		print('NO')


from sys import stdin, stdout

def solve():
	(n, m, a, b) = map(int, stdin.readline().split())
	if n * a != m * b:
		stdout.write('NO\n')
		return
	else:
		stdout.write('YES\n')
		idx = 0
		for _ in range(n):
			row = [0] * m
			c = 0
			while c < a:
				row[idx] = 1
				idx = (idx + 1) % m
				c += 1
			for c in range(m):
				stdout.write(str(row[c]))
			stdout.write('\n')
for _ in range(int(stdin.readline())):
	solve()


t = int(input())
for _ in range(t):
	(h, w, h_cnt, w_cnt) = map(int, input().split())
	if h_cnt * h != w_cnt * w:
		print('NO')
		continue
	ans = [[0] * w for i in range(h)]
	j = 0
	for i in range(h):
		cnt = h_cnt
		while cnt > 0:
			ans[i][j % w] = 1
			j += 1
			cnt -= 1
	print('YES')
	for res in ans:
		print(''.join(map(str, res)))


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin
t = int(input())
for ti in range(1, t + 1):
	(r, c, a, b) = list(map(int, input().split()))
	if r * a == c * b:
		print('YES')
		t = '1' * a + '0' * (c - a)
		for i in range(r):
			print(t)
			t = t[c - a:] + t[:c - a]
	else:
		print('NO')


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

def solve():
	(n, m, a, b) = list(map(int, input().split(' ')))
	if a * n != b * m:
		print('NO')
		return
	arr = [[0 for i in range(m)] for j in range(n)]
	index = 0
	current = 0
	for i in range(n):
		for j in range(a):
			arr[i][(current + j) % m] = 1
		current = (current + a) % m
	print('YES')
	for m in arr:
		print(''.join([str(x) for x in m]))
main()


t = int(input())
for i in range(t):
	(n, m, a, b) = list(map(int, input().split()))
	if n * a == m * b:
		print('YES')
		matrix = [['0'] * m for j in range(n)]
		col = 0
		for row in range(n):
			tot = 0
			while True:
				if tot == a:
					break
				matrix[row][col] = '1'
				col += 1
				tot += 1
				col %= m
			col %= m
		for ma in matrix:
			print(''.join(ma))
	else:
		print('NO')


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
for _ in range(inp()):
	(n, m, a, b) = ip()
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	row = ['0' for i in range(m)]
	for i in range(a):
		row[i] = '1'
	mat = []
	for i in range(n):
		mat.append(row)
		row = row[a:] + row[:a]
	[print(''.join(i)) for i in mat]


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

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

def read_int_array():
	return [int(_) for _ in read_string_array()]

def read_line():
	return input()

def solve(n, m, a, b):
	mat = []
	row = [1 if _ < a else 0 for _ in range(m)]
	for _ in range(n):
		mat.append(row)
		row = row[a:] + row[:a]
	rows = [sum(_) != a for _ in mat]
	cols = [sum((mat[j][i] for j in range(n))) != b for i in range(m)]
	if any(rows) or any(cols):
		return None
	return mat
T = read_int()
for _ in range(T):
	(N, M, A, B) = read_int_array()
	sol = solve(N, M, A, B)
	if sol is None:
		print('NO')
	else:
		print('YES')
		for line in sol:
			print(''.join((str(_) for _ in line)))


a = int(input())
for i in range(a):
	(n, m, a, b) = map(int, input().split())
	if m * b != n * a:
		print('NO')
	else:
		print('YES')
		ans = [[0 for i in range(m)] for i in range(n)]
		count = 0
		for i in range(n):
			temp = ans[i]
			for j in range(a):
				temp[(count + j) % m] = 1
			count += a
		for i in range(n):
			x = ans[i]
			print(''.join(map(str, x)))


for i in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	x = m - a
	(s, t) = ('', '1' * a + '0' * x)
	for i in range(n):
		s += '\n' + t
		t = t[x:] + t[:x]
	print('YES' + s if n * a == m * b else 'NO')


n = int(input())
for x in range(n):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	l = [[0, x] for x in range(m)]
	l_out = [[0 for z in range(m)] for zz in range(n)]
	row = 0
	col = 0
	b_no = False
	while True:
		for y in range(b):
			l_out[row][col] = 1
			row += 1
			if row > n - 1:
				row = 0
		col += 1
		if col > m - 1:
			break
	print('YES')
	for y in l_out:
		print(''.join([str(x) for x in y]))


import sys
max_int = 1000000001
min_int = -max_int
t = int(input())
for _t in range(t):
	(n, m, a, b) = map(int, sys.stdin.readline().split())
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	pointer = -1
	for i in range(n):
		row = ['0'] * m
		for j in range(a):
			pointer = (pointer + 1) % m
			row[pointer] = '1'
		print(''.join(row))


t = int(input())
for _ in range(t):
	(n, m, a, b) = [int(ipt) for ipt in input().split()]
	if a * n != b * m:
		print('NO')
		continue
	ret = [['0'] * m for _ in range(n)]
	for i in range(n):
		for j in range(i * a, (i + 1) * a):
			ret[i][j % m] = '1'
	print('YES')
	for i in range(n):
		print(''.join([ret[i][j] for j in range(m)]))


INF = 10 ** 18
t = int(input())

def cicle(s, x):
	s1 = s[0:len(s) - x]
	s2 = s[len(s) - x:]
	return s2 + s1

def solve():
	(n, m, a, b) = map(int, input().split())
	if a * n != b * m:
		print('NO')
		return
	print('YES')
	ans = []
	s = str()
	for i in range(a):
		s += '1'
	for i in range(m - a):
		s += '0'
	for i in range(n):
		ans.append(s)
		s = cicle(s, a)
	for i in range(n):
		print(ans[i])
for tt in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	mt = [[0] * m for i in range(n)]
	if n * a != m * b:
		print('NO')
	else:
		cur = 0
		for i in range(n):
			for j in range(a):
				mt[i][(cur + j) % m] = 1
			cur = (cur + a) % m
		print('YES')
		for i in mt:
			print(''.join(map(str, i)))


t = int(input())
while t != 0:
	t -= 1
	(n, m, a, b) = map(int, input().split())
	if b * m == a * n:
		print('YES')
		s = '0' * (m - a) + '1' * a
		for _ in range(n):
			print(s)
			s = s[m - a:] + s[:m - a]
	else:
		print('NO')


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	(n, m, a, b) = M()
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		l = []
		for i in range(n):
			l.append([0] * m)
		sr = 0
		sc = 0
		i = 0
		while i < n:
			for j in range(sc, sc + a):
				l[i % n][j % m] = 1
			sc += a
			i += 1
		for i in range(n):
			for j in range(m):
				print(l[i][j], end='')
			print()


t = int(input())
while t > 0:
	(n, m, a, b) = map(int, input().split())
	if n * a != b * m:
		print('NO')
		t -= 1
		continue
	print('YES')
	out = [1] * a
	out.extend([0] * (m - a))
	for i in range(n):
		j = a * i
		j %= m
		print(*out[j:], *out[:j], sep='')
	t -= 1


import sys
import math

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

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

def printspx(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')

def printchk(*args):
	return print(*args, end=' \\ ')
MODPRIME = int(1000000000.0 + 7)
BABYMOD = 998244353

def __starting_point():
	for _testcases_ in range(int(input())):
		(n, m, a, b) = get_ints()
		if m / a != n / b:
			print('NO')
		else:
			print('YES')
			matr = [[0] * m for x in range(n)]
			fac = math.ceil(m / a)
			for i in range(n):
				for j in range(a):
					matr[i][(j + i * a) % m] = 1
			for i in range(n):
				for j in range(m):
					printspx(matr[i][j])
				print()
__starting_point()


import sys, math
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m, a, b) = map(int, sys.stdin.readline().split())
	A = [[0] * m for i in range(n)]
	if n * a == m * b or n / m == b / a:
		print('YES')
		k = -1
		for i in range(1, m):
			if i * n % m == 0:
				k = i
				break
		for i in range(n):
			for j in range(k * i, k * i + a):
				A[i][j % m] = 1
		for i in range(n):
			for j in range(m):
				print(A[i][j], end='')
			print()
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(H, W, a, b) = list(map(int, input().split()))
	if a * H != b * W:
		print('NO')
	else:
		print('YES')
		ans = [[0] * W for _ in range(H)]
		L = 0
		for y in range(H):
			for x in range(L, L + a):
				ans[y][x % W] = 1
			L += W - a
		for c in ans:
			print(''.join(map(str, c)))


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

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

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

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

def yuh(N, M, A, B):
	times = 1
	for a in range(1, M + 1):
		if a * N % M == 0:
			times = a
			break
	original_start = 0
	original_end = A - 1
	for i in range(N):
		start = (i * times + original_start) % M
		end = (i * times + original_end) % M
		for j in range(M):
			if end < start:
				if j >= start or j <= end:
					value = 1
				else:
					value = 0
				if j == M - 1:
					print(value)
				else:
					print(value, end='')
			else:
				if j >= start and j <= end:
					value = 1
				else:
					value = 0
				if j == M - 1:
					print(value)
				else:
					print(value, end='')
test_cases = inp()
for test in range(test_cases):
	(N, M, A, B) = inlt()
	if N * A != M * B:
		print('NO')
		continue
	else:
		print('YES')
		yuh(N, M, A, B)


import sys

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

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

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

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

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

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

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

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

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(H, W, a, b) = MAP()
	swapped = False
	if H > W:
		(H, W) = (W, H)
		(a, b) = (b, a)
		swapped = True
	if H * a != W * b:
		NO()
		continue
	if H * W < a * b:
		NO()
		continue
	grid = list2d(H, W, 0)
	j = 0
	for i in range(H):
		for _ in range(a):
			grid[i][j] = 1
			j = (j + 1) % W
	if swapped:
		grid = list(zip(*grid))
		(H, W) = (W, H)
	YES()
	for i in range(H):
		print(''.join(map(str, grid[i])))


import sys
input = sys.stdin.readline

def is_valid(mat, a, b):
	sum_cols = [0] * len(mat[0])
	for r in range(len(mat)):
		for c in range(len(mat[0])):
			sum_cols[c] += mat[r][c]
		if sum(mat[r]) != a:
			return False
	for s in sum_cols:
		if s != b:
			return False
	return True

def solve(n, m, a, b):
	if a > m or b > n:
		print('NO')
	mat = [[0] * m for _ in range(n)]
	r_i = 0
	for r in range(n):
		for _ in range(a):
			mat[r][r_i] = 1
			r_i = (r_i + 1) % m
	if is_valid(mat, a, b):
		print('YES')
		for row in mat:
			print(''.join(map(str, row)))
	else:
		print('NO')
t = int(input().strip())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	solve(n, m, a, b)


for s in [*open(0)][1:]:
	(n, m, a, b) = map(int, s.split())
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	c = [[0] * m for i in range(n)]
	d = 0
	for i in range(n):
		for j in range(a):
			c[i][d % m] = 1
			d += 1
	for x in c:
		print(*x, sep='')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if a * n != b * m or a > m or b > n:
		print('NO')
	else:
		print('YES')
		ans = '1' * a + '0' * (m - a)
		ans *= 100
		for i in range(n):
			print(ans[i * a:i * a + m])


import sys
input = lambda : sys.stdin.readline().strip()

def solve():
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		return
	ans = [[0] * m for _ in range(n)]
	shift = 0
	while shift + 1 < m:
		shift += 1
		if shift * n % m == 0:
			break
	dx = 0
	for i in range(n):
		for j in range(a):
			ans[i][(j + dx) % m] = 1
		dx += shift
	print('YES')
	for i in range(n):
		for j in range(m):
			print(ans[i][j], end='')
		print()
t = int(input())
while t:
	t -= 1
	solve()


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

def quick_gcd(a, b):
	for i in range(min(a, b), 0, -1):
		if a % i == 0 and b % i == 0:
			return i

def go():
	(n, m, a, b) = map(int, input().split())
	if n * a != b * m:
		return 'NO'
	row = '1' * a + '0' * (m - a)
	res = []
	g = quick_gcd(m, a)
	pos = 0
	for i in range(n):
		cur = row[pos:] + row[:pos]
		res.append(cur)
		pos = (pos + g) % m
	return 'YES' + '\n' + '\n'.join(res)
t = int(input())
ans = []
for _ in range(t):
	ans.append(str(go()))
print('\n'.join(ans))


import sys, heapq
from collections import *
from functools import lru_cache
sys.setrecursionlimit(10 ** 6)

def main():
	t = int(input())
	for _ in range(t):
		(n, m, r, c) = map(int, input().split(' '))
		start = 0
		dp = [[0] * m for _ in range(n)]
		flag = True
		for i in range(n):
			for j in range(start, start + r):
				dp[i][j % m] = 1
				if j // m + 1 > c:
					flag = False
					break
			start += r
		if start % m or start // m != c:
			flag = False
		if flag:
			print('YES')
			for i in range(n):
				print(''.join(map(str, dp[i])))
		else:
			print('NO')
main()


t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		arr = [['0'] * m for i in range(n)]
		idx = 0
		for i in range(n):
			for j in range(a):
				arr[i][idx] = '1'
				idx += 1
				idx %= m
		print('YES')
		for i in arr:
			print(''.join(i))


import sys
T = int(sys.stdin.readline().strip())
for t in range(T):
	(n, m, a, b) = map(int, sys.stdin.readline().strip().split(' '))
	if n * a != m * b:
		print('NO')
		continue
	res = [['0' for _ in range(m)] for _ in range(n)]
	pt = 0
	for i in range(n):
		for j in range(a):
			res[i][pt] = '1'
			pt = (pt + 1) % m
	print('YES')
	for i in range(n):
		print(''.join(res[i]))


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		colms = [0] * m
		k = 0
		j = -1
		for i in range(n):
			t = a
			ct = a
			l1 = [0] * m
			while ct:
				j += 1
				l1[j % m] = 1
				ct -= 1
			for j2 in l1:
				print(j2, end='')
			print()


def solve(n, m, a, b, ans):
	col = 0
	grid = [[0 for j in range(m)] for i in range(n)]
	for row in range(n):
		count = 0
		while count != a:
			grid[row][col] = 1
			col += 1
			count += 1
			if col == m:
				col = 0
	for row in range(n):
		count = 0
		for col in range(m):
			if grid[row][col] == 1:
				count += 1
		if count != a:
			ans.append(['NO'])
			return
	for col in range(m):
		count = 0
		for row in range(n):
			if grid[row][col] == 1:
				count += 1
		if count != b:
			ans.append(['NO'])
			return
	ans.append(['YES'])
	for row in range(n):
		s = ''
		for col in grid[row]:
			s += str(col)
		ans.append([s])

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, m, a, b) = list(map(int, input().split()))
		solve(n, m, a, b, ans)
	for i in ans:
		for j in i:
			print(j)
main()


import math
t = int(input())

def convert(s):
	new = ''
	for x in s:
		new += x
	return new
for i in range(t):
	(n, m, a, b) = map(int, input().split())
	if m * b != n * a:
		print('NO')
	else:
		print('YES')
		l = 0
		for j in range(n):
			ans = ['0'] * m
			for k in range(a):
				ans[(l + k) % m] = '1'
			print(convert(ans))
			l += math.gcd(a, m)


t = int(input())
for i in range(t):
	num1 = list(map(int, input().split()))
	n = num1[0]
	m = num1[1]
	a = num1[2]
	b = num1[3]
	if a * n == b * m:
		print('YES')
		j = 0
		matrix = [[0 for k in range(m)] for l in range(n)]
		for k in range(n):
			for l in range(a):
				matrix[k][(k * a + l) % m] = 1
		for k in range(n):
			s = ''
			for l in range(m):
				s += str(matrix[k][l])
			print(s)
	else:
		print('NO')


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a == m * b:
		ans = '1' * a + '0' * (m - a)
		print('YES')
		for i in range(n):
			ans = ans[m - a:] + ans[:m - a]
			print(ans)
	else:
		print('NO')


def listToString(sx):
	str1 = ''
	for ele in sx:
		str1 += ele
	return str1
for t in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if a * n != b * m:
		print('NO')
	else:
		print('YES')
		for e in range(1, m + 1):
			if e * n % m == 0:
				c = e
				break
		s = []
		x = ['1'] * a
		q = ['0'] * (m - a)
		x.extend(q)
		y = ''
		y = listToString(x)
		for i in range(0, n):
			s.append(y)
			x = x[-c:] + x[:-c]
			y = ''
			y = listToString(x)
		for i in range(n):
			print(*s[i], sep='')


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != b * m:
		print('NO')
	else:
		print('YES')
		z = m - a
		st = '1' * a + '0' * z
		st *= 2
		for i in range(n):
			print(st[a * i % m:m + a * i % m])


def gcd(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b
t = int(input())
for iterator in range(t):
	(n, m, a, b) = (int(i) for i in input().split())
	if m / a == n / b:
		print('YES')
		if m != n:
			g = gcd(m, n)
			c = a / (m / g)
		else:
			g = min(n, m)
			c = a
		for i in range(n):
			print(''.join(['1' if (j - i) % g < c else '0' for j in range(m)]))
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, x, y) = map(int, input().split())
	f = 0
	l = []
	if n * x != m * y:
		print('NO')
		continue
	l.append('1' * x + '0' * (m - x))
	for i in range(n - 1):
		s = l[-1]
		r = n % x
		l.append(s[m - x:] + s[:m - x])
	ans = 'YES'
	c = 0
	c1 = 0
	print(ans)
	for i in l:
		print(i)


import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs = lambda : input()
ri = lambda : int(input())
rm = lambda : map(int, input().split())
rai = lambda : [int(x) for x in input().split()]

def solve():
	if R * h1 != C * v1:
		print('NO')
	else:
		print('YES')
		ans = [[0 for j in range(C)] for i in range(R)]
		for r in range(R):
			for c in range(h1 * r, h1 * (r + 1)):
				ans[r][c % C] = 1
		for i in range(R):
			for j in range(C):
				print(str(ans[i][j]), end='')
			print()
for t in range(ri()):
	(R, C, h1, v1) = rm()
	solve()


import sys
import heapq
import random
import collections
from functools import lru_cache

def solve(n, m, a, b):
	console(n, m, a, b)
	if n * a != m * b:
		console('case 1b', n / b, m / a)
		return 'NO'
	res = []
	t = '1' * a + '0' * (m - a)
	for i in range(n):
		res.append(t)
		t = t[m - a:] + t[:m - a]
	return 'YES\n' + '\n'.join(res)

def console(*args):
	return
for case_num in range(int(input())):
	(n, m, a, b) = list(map(int, input().split()))
	res = solve(n, m, a, b)
	print(res)


from sys import stdin, stdout
for case in range(int(stdin.readline())):
	(n, m, a, b) = [int(x) for x in stdin.readline().split()]
	if n * a != m * b:
		print('NO')
		continue
	out = []
	for x in range(n):
		new = [0 for a in range(m)]
		for c in range(x * a, x * a + a):
			new[c % m] = 1
		out.append(new)
	print('YES')
	for y in out:
		outS = ''
		for x in y:
			outS += str(x)
		print(outS)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if a * n != b * m:
		print('NO')
		continue
	print('YES')
	for s in range(m):
		found = True
		grid = [[0] * m for i in range(n)]
		for i in range(n):
			for j in range(a):
				grid[i][(j + s * i) % m] = 1
		for j in range(m):
			c = 0
			for i in range(n):
				c += grid[i][j]
			if c != b:
				found = False
		if found:
			for row in grid:
				print(''.join([str(i) for i in row]))
			break


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		ar = []
		for i in range(n):
			ar.append([0] * m)
		j = 0
		for i in range(n):
			temp = a
			while temp > 0:
				if j == m:
					j = 0
				ar[i][j] = 1
				j += 1
				temp -= 1
		print('YES')
		for i in ar:
			for j in i:
				print(j, end='')
			print()


t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	ar = [[0 for j in range(m)] for i in range(n)]
	st = 0
	for i in range(n):
		for j in range(a):
			ar[i][(st + j) % m] = 1
		st = st + a
		st %= m
	flag = 1
	for i in range(n):
		count = 0
		for j in range(m):
			if ar[i][j] == 1:
				count += 1
		if count != a:
			flag = 0
	for i in range(m):
		count = 0
		for j in range(n):
			if ar[j][i] == 1:
				count += 1
		if count != b:
			flag = 0
	if flag == 0:
		print('NO')
	else:
		print('YES')
		for i in range(n):
			for j in range(m):
				print(ar[i][j], end='')
			print('')


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('No')
		continue
	print('Yes')
	t = '1' * a + '0' * (m - a)
	for i in range(n):
		print(t)
		t = t[m - a:] + t[:m - a]


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, m, a, b) = map(int, input().split())
		if a * n != m * b:
			print('NO')
			continue

		def solve(a, b):
			ans = [[False for _ in range(m)] for _ in range(n)]
			cnt = [0] * n
			pq = [i for i in range(n)]
			for r in range(m):
				cur = 0
				pq.sort(key=lambda x: cnt[x])
				for c in pq:
					if cur == b:
						break
					if cnt[c] >= a:
						continue
					cnt[c] += 1
					cur += 1
					ans[c][r] = True
				if cur < b:
					return False
			print('YES')
			for v in ans:
				print(''.join(('%d' % x for x in v)))
			return True
		if solve(a, b):
			continue
		print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


t = int(input())
for i in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	shift = 0
	for j in range(1, m):
		if j * n % m == 0:
			shift = j
			break
	col = [j for j in range(a)]
	ans = [[0 for j in range(m)] for k in range(n)]
	for j in range(n):
		for k in col:
			ans[j][k] = 1
		for k in range(m):
			print(ans[j][k], end='')
		print('')
		col = [(x + shift) % m for x in col]


import math
T = int(input())
for _ in range(T):
	(n, m, a, b) = list(map(int, input().split()))
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		ans = []
		for i in range(n):
			brk = i * a % m
			line = '1' * a + '0' * (m - a)
			line = line[brk:] + line[:brk]
			ans.append(line)
		print('\n'.join(ans))


TT = int(input())
for loop in range(TT):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	elif n * (m - a) != m * (n - b):
		print('NO')
		continue
	onum = n * a
	znum = n * (m - a)
	if onum + znum != n * m:
		print('NO')
		continue
	ans = [['0'] * m for i in range(n)]
	nl = [a] * n
	ml = [b] * m
	li = 0
	for i in range(n):
		for j in range(a):
			ans[i][li] = '1'
			nl[i] -= 1
			ml[li] -= 1
			li += 1
			li %= m
	if max(nl) == 0 and min(nl) == 0 and (max(ml) == 0) and (min(ml) == 0):
		print('YES')
		for i in ans:
			print(''.join(i))
		continue
	else:
		print('NO')


from collections import *
from bisect import *
from math import *
from heapq import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, m, a, b) = map(int, input().split())
	ma = [[0 for i in range(m)] for j in range(n)]
	x = -a
	flag = 0
	for i in range(n):
		x = (x + a) % m
		for j in range(x, min(x + a, m)):
			ma[i][j] = 1
		re = a - (m - x)
		for j in range(re):
			ma[i][j] = 1
	for i in range(m):
		cc = 0
		for j in range(n):
			if ma[j][i] == 1:
				cc += 1
		if cc != b:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')
		for i in ma:
			for j in i:
				print(j, end='')
			print()


import sys
import math
t = int(sys.stdin.readline().strip())
for i in range(t):
	(n, m, a, b) = list(map(int, sys.stdin.readline().strip().split(' ')))
	if a * n != m * b:
		print('NO')
	else:
		grid = [[0 for _ in range(m)] for _ in range(n)]
		if m % a == 0:
			start = 0
			cnt = 0
			for i in range(n):
				for j in range(start, start + a):
					grid[i][j] = 1
				cnt += 1
				if cnt == b:
					cnt = 0
					start += a
		else:
			start = 0
			for i in range(n):
				for j in range(start, start + a):
					grid[i][j % m] = 1
				start = (start + a) % m
		print('YES')
		for l in grid:
			print(''.join(list(map(str, l))))


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if a * n != b * m:
		print('NO')
		continue
	else:
		print('YES')
		mat = [['0' for j in range(m)] for i in range(n)]
		for i in range(n):
			for j in range(a):
				mat[i][(i * a + j) % m] = '1'
		for elem in mat:
			print(''.join(elem))


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if a > m or b > n or n / m != b / a:
		print('NO')
	else:
		print('YES')
		x = [['0' for j in range(m)] for i in range(n)]
		j = 0
		for i in range(m):
			p = 0
			while p < b:
				x[j][i] = '1'
				j = (j + 1) % n
				p += 1
		for i in range(n):
			print(''.join(x[i]))


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	ans = []
	for i in range(n):
		ans.append([0] * m)
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	cl = [0] * m
	for i in range(n):
		for j in range(a):
			ind = cl.index(min(cl))
			ans[i][ind] = 1
			cl[ind] += 1
	for i in ans:
		print(''.join(map(str, i)))


from math import sqrt
from collections import defaultdict as dd, deque
import sys
input = sys.stdin.readline
t = int(input())
while t:
	ll = []
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		res = [[0] * m for j in range(n)]
		for i in range(n):
			for j in range(i * a % m, a + i * a % m):
				j = j % m
				res[i][j] = 1
		print('YES')
		for i in res:
			print(*i, sep='')
	t -= 1


from math import *
t = int(input())
m = []
for i in range(t):
	x = list(map(int, input().split()))
	m.append(x)
for i in range(t):
	flag = 0
	if m[i][0] * m[i][2] == m[i][1] * m[i][3] and m[i][0] >= m[i][3] and (m[i][1] >= m[i][2]):
		flag = 1
		print('YES')
		gcd_r = gcd(m[i][0], m[i][3])
		r1 = int(m[i][0] / gcd_r)
		r2 = int(m[i][3] / gcd_r)
		gcd_c = gcd(m[i][1], m[i][2])
		c1 = int(m[i][1] / gcd_c)
		c2 = int(m[i][2] / gcd_c)
		qq = []
		qq += r2 * ['1']
		qq += (r1 - r2) * ['0']
		qqq = []
		for kk in range(int(m[i][1] / r1)):
			qqq = qqq + qq
		q4 = []
		str1 = []
		for kk in range(r1):
			qqq.append(qqq.pop(0))
			q4.append(qqq[:])
			str1.append(''.join(q4[kk]))
		for kk in range(m[i][0]):
			print(str1[kk % r1])
	else:
		print('No')


import sys
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(n, m, a, b) = invr()
	if n * a != m * b:
		print('NO')
		continue
	else:
		print('YES')
	ans = [[0 for i in range(m)] for j in range(n)]
	d = 0
	for i in range(1, m):
		if i * n % m == 0:
			d = i
			break
	now = 0
	for i in range(n):
		for j in range(a):
			ans[i][(now + j) % m] = 1
		now += d
	for i in range(n):
		for j in range(m):
			print(ans[i][j], end='')
		print()


from math import sqrt
from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for t in range(test):
		l = [int(i) for i in input().split(' ')]
		n = l[0]
		m = l[1]
		a = l[2]
		b = l[3]
		matrix = [[0 for i in range(m)] for i in range(n)]
		col = 0
		for i in range(n):
			if col == m:
				col = 0
			j = 0
			while j < a:
				if col == m:
					col = 0
				matrix[i][col] = 1
				j += 1
				col += 1
		flag = True
		for j in range(m):
			one = 0
			for i in range(n):
				if matrix[i][j] == 1:
					one += 1
			if one != b:
				flag = False
				break
		if flag:
			print('YES')
			for i in range(n):
				for j in range(m):
					print(matrix[i][j], end='')
				print()
		else:
			print('NO')
main()


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

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def solve():
	for _ in range(ii()):
		(n, m, a, b) = mi()
		c = 0
		x = [['0' for j in range(m)] for i in range(n)]
		for i in range(n):
			for j in range(c, min(c + a, m)):
				x[i][j] = '1'
			for j in range(max(0, c + a - m)):
				x[i][j] = '1'
			if c + a > m:
				c = c + a - m
			else:
				c += a
		f = 1
		for i in range(n):
			if a != x[i].count('1'):
				f = 0
		for i in range(m):
			p = []
			for j in range(n):
				p.append(x[j][i])
			if b != p.count('1'):
				f = 0
		if f:
			print('YES')
			for i in range(n):
				print(''.join(x[i]))
		else:
			print('NO')
solve()


t = int(input())

def compute_hcf(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for i in range(t):
	(n, m, a, b) = list(map(int, input().split()))
	if a * n != m * b:
		print('NO')
	else:
		print('YES')
		y_mov = compute_hcf(m, a)
		x_mov = compute_hcf(n, b)
		mat = ''
		for i in range(n):
			for j in range(m):
				if i // x_mov * y_mov + a < m:
					if i // x_mov * y_mov <= j < i // x_mov * y_mov + a:
						mat += '1'
					else:
						mat += '0'
				elif j < (i // x_mov * y_mov + a) % m or j >= i // x_mov * y_mov:
					mat += '1'
				else:
					mat += '0'
			mat += '\n'
		print(mat)


from sys import stdin, stdout
T = int(input())
while T:
	(n, m, a, b) = map(int, input().split())
	arr = [['0' for col in range(m)] for row in range(n)]
	countColArr = [0 for col in range(m)]
	for i in range(n):
		for j in range(a):
			arr[i][(a * i + j) % m] = '1'
			countColArr[(a * i + j) % m] += 1
	flag = True
	for i in range(m):
		if countColArr[i] != b:
			flag = False
			break
	if flag:
		stdout.write('YES' + '\n')
		for i in range(n):
			stdout.write(''.join(arr[i]) + '\n')
	else:
		stdout.write('NO' + '\n')
	T -= 1


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, m, a, b) = map(int, input().split())
	ans = [[0] * m for _ in range(n)]
	if n * a != m * b:
		print('NO')
	else:
		tracker = 0
		for j in range(n):
			for k in range(a):
				ans[j][tracker] = 1
				tracker += 1
				tracker %= m
		print('YES')
		for j in ans:
			j = ''.join(map(str, j))
			print(j)


n = int(input())
for _ in range(n):
	(x, y, a, b) = map(int, input().split())
	if x * a != y * b:
		print('NO')
	else:
		print('YES')
		arr = [[0 for i in range(y)] for j in range(x)]
		j = 0
		for i in range(x):
			ct = 0
			if j >= y:
				j = 0
			for k in range(y):
				if ct < a:
					if j >= y:
						j = 0
					arr[i][j] = 1
					j += 1
					ct += 1
				else:
					break
		for i in range(x):
			for j in range(y):
				print(arr[i][j], end='')
			print()


t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	else:
		print('YES')
	n1 = n
	m1 = m
	a1 = a
	b1 = b
	while n1 > 0 and b1 > 0:
		if n1 > b1:
			n1 %= b1
		else:
			b1 %= n1
	x = n1 + b1
	c = n // x
	k = 0
	for i in range(0, c):
		s = ''
		for j in range(0, m):
			if j >= k and j < k + a or j < k + a - m:
				s += '1'
			else:
				s += '0'
		k = (k + a) % m
		for _ in range(x):
			print(s)


n = input('')
n = int(n)
str = []
for i in range(n):
	entries = list(map(int, input().split()))
	str.append(entries)
for i in str:
	row = i[0]
	column = i[1]
	a = i[2]
	b = i[3]
	if row * a != column * b:
		print('NO')
	else:
		print('YES')
		dis = 0
		col_ind = 0
		row_ind = 0
		final_matrix = []
		for k in range(1, column + 1, 1):
			if k * row % column == 0:
				dis = k
				break
		for l in range(row):
			mat = ['0'] * column
			for j in range(a):
				col_ind = (row_ind + j) % column
				mat[col_ind] = '1'
			row_ind = row_ind + dis
			final_matrix.append(mat)
		for i in range(row):
			print(''.join(final_matrix[i]))


from sys import stdin, stdout
from collections import Counter, deque
from bisect import bisect_left
from itertools import product
T = int(input())
for _ in range(T):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue

	def gcd(a, b):
		return a if b == 0 else gcd(b, a % b)
	(bl, wh) = (n * a, n * m - n * a)
	g = gcd(bl, wh)
	(bl, wh) = (bl // g, wh // g)
	mx = [[0] * m for _ in range(n)]
	for r in range(n):
		for c in range(m):
			p = (r * m + c) % (bl + wh)
			mx[r][(r + c) % m] = 1 if p < bl else 0
	print('YES')
	for row in mx:
		print(''.join(map(str, row)))


def solve():
	if not n * a == m * b:
		print('NO')
		return
	ans = [[0 for _ in range(m)] for _ in range(n)]
	colsum = [0] * m
	for i in range(n):
		inds = sorted(range(m), key=lambda x: colsum[x])[:a]
		for j in inds:
			colsum[j] += 1
			ans[i][j] = 1
	print('YES')
	for ai in ans:
		print(*ai, sep='')
	return
t = int(input())
for tt in range(1, t + 1):
	(n, m, a, b) = [int(i) for i in input().split(' ')]
	solve()


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	m = int(l[1])
	a = int(l[2])
	b = int(l[3])
	arr = [[0 for i in range(m)] for i in range(n)]
	if n * a != m * b:
		print('NO')
	else:
		diff = 1
		for i in range(n):
			for j in range(a):
				arr[i][(i * a + j) % m] = 1
		print('YES')
		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, a, b) = [int(ipt) for ipt in input().split()]
	if a * n != b * m:
		print('NO')
		continue
	if a < b:
		flip = True
		(n, m, a, b) = (m, n, b, a)
	else:
		flip = False
	ret = [['0'] * m for _ in range(n)]
	d = a
	for i in range(n):
		for j in range(i * d, i * d + a):
			ret[i][j % m] = '1'
	print('YES')
	if flip:
		for j in range(m):
			print(''.join([ret[i][j] for i in range(n)]))
	else:
		for i in range(n):
			print(''.join([ret[i][j] for j in range(m)]))


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, m, a, b):
	if n * a != m * b:
		return None
	total_ones = 0
	result = [[0 for x in range(m)] for y in range(n)]
	for i in range(n):
		for j in range(a):
			result[i][total_ones % m] = 1
			total_ones += 1
	return result
for i in tests():
	(n, m, a, b) = arr_in()
	result = solve(n, m, a, b)
	out('YES' if result is not None else 'NO')
	if result is not None:
		for row in result:
			out(''.join(map(str, row)))


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
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')
if not is_it_local():
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

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

def check(n, m, res, a, b):
	for i in range(n):
		cnt = 0
		for j in range(m):
			cnt += res[i][j]
		if cnt != a:
			return False
	for i in range(m):
		cnt = 0
		for j in range(n):
			cnt += res[j][i]
		if cnt != b:
			return False
	return True

def main():
	t = input1()
	for ci in range(t):
		[n, m, a, b] = input_array()
		row = [0 for _ in range(n)]
		res = [[0 for _ in range(m)] for _ in range(n)]
		k = 0
		for i in range(n):
			for j in range(a):
				res[i][k % m] = 1
				k += 1
		if check(n, m, res, a, b):
			print('YES')
			for i in range(n):
				now = ''.join(map(str, res[i]))
				print(now)
		else:
			print('NO')
	pass
READ('in.txt')
main()


def solve():
	t = int(input())
	for _ in range(t):
		(n, m, a, b) = map(int, input().split())
		if n * a != m * b:
			print('NO')
			continue
		else:
			print('YES')
			ma = [[0 for i in range(m)] for j in range(n)]
			for i in range(n):
				start = i * a
				for j in range(a):
					ma[i][(j + start) % m] = 1
			for i in ma:
				for j in i:
					print(j, end='')
				print()
solve()


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		tt = '1' * a + '0' * (m - a)
		for _ in range(n):
			print(tt)
			tt = tt[m - a:] + tt[:m - a]


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

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

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		(n, m, a, b) = RL()
		res = [[0] * m for _ in range(n)]
		if n * a != m * b:
			print('NO')
		else:
			now = 0
			for i in range(n):
				for j in range(a):
					res[i][now] = 1
					now += 1
					now %= m
			print('YES')
			for i in res:
				print(''.join([str(j) for j in i]))
main()


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

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

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

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

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

def solve():
	(n, m, a, b) = invr()
	if a * n == m * b:
		print('YES')
		q = [['0'] * m for i in range(n)]
		w = 0
		for i in range(n):
			for j in range(a):
				q[i][w] = '1'
				w = (w + 1) % m
		print(*[''.join(q[i]) for i in range(n)], sep='\n')
	else:
		print('NO')

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	ans = [['0'] * m for _ in range(n)]
	s = 0
	for i in range(m):
		if n * i % m == 0:
			d = i
	for i in range(n):
		for j in range(s, s + a):
			ans[i][j % m] = '1'
		s += d
	print('YES')
	for ans_i in ans:
		print(''.join(ans_i))


for i in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	ones = a * n
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		pos = 0
		for k in range(n):
			ans = ['0'] * m
			for j in range(pos, pos + a):
				ans[j % m] = '1'
			print(''.join(ans))
			pos += a


T = int(input())
for _ in range(T):
	(N, M, A, B) = map(int, input().split())
	if M * B != N * A:
		print('NO')
	else:
		print('YES')
		offset = 0
		for _ in range(N):
			ans = ['0'] * M
			for i in range(offset, offset + A):
				ans[i % M] = '1'
			offset += A
			print(''.join(ans))


from sys import stdin
input = stdin.readline
for Ti in range(int(input().strip())):
	(n, m, a, b) = [int(x) for x in input().strip().split()]
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		f = [['0'] * m for _ in range(n)]
		(i, j, rc) = (0, 0, 0)
		cnt = n * a
		while cnt:
			f[i][j] = '1'
			rc += 1
			j += 1
			if not j % m:
				j = 0
			if not rc % a:
				i += 1
				rc = 0
			cnt -= 1
		for fi in f:
			print(''.join(fi))


from sys import stdin, stdout

def find(N, M, A, B):
	if A * N != B * M:
		return 'NO'
	arr = [[0] * M for _ in range(N)]
	(j, k) = (0, 0)
	for i in range(N):
		(a, b) = (max(0, j + A - M), min(M, j + A) - j)
		for x in range(a):
			arr[i][x] = 1
		for x in range(b):
			arr[i][j + x] = 1
		j = (A + j) % M
	res = 'YES\n'
	res += '\n'.join([''.join(map(str, x)) for x in arr])
	return res

def main():
	for _ in range(int(stdin.readline())):
		(N, M, A, B) = list(map(int, stdin.readline().split()))
		print(find(N, M, A, B))
main()


def solve(n, m, a, b):
	if n * a != m * b:
		print('NO')
		return
	arr = [[0 for j in range(0, m)] for i in range(0, n)]
	start = 0
	for i in range(0, n):
		for j in range(0, a):
			idx = (start + j) % m
			arr[i][idx] = 1
		start += a
	print('YES')
	for i in range(0, n):
		print(''.join(map(str, arr[i])))
	return
t = int(input())
for i in range(t):
	(n, m, a, b) = map(int, input().split())
	solve(n, m, a, b)


for t in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a == m * b:
		print('YES')
		sub = ['1'] * a + ['0'] * (m - a)
		for i in range(n):
			sub = sub[a:] + sub[:a]
			print(''.join(sub))
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, a, b) = list(map(int, input().split()))
	if a * n != b * m:
		print('NO')
	else:
		ar = []
		for i in range(n):
			ar.append([0] * m)
		(x, y) = (0, a)
		for i in range(n):
			if x < y:
				for j in range(x, y):
					ar[i][j] = 1
			else:
				for j in range(x, m):
					ar[i][j] = 1
				for j in range(y):
					ar[i][j] = 1
			x += a
			y += a
			x %= m
			y %= m
		print('YES')
		for i in range(n):
			print(''.join(map(str, ar[i])))


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
		continue
	print('YES')
	arr = [[0] * m for i in range(n)]
	j = 0
	for i in range(n):
		for k in range(a):
			arr[i][j] = 1
			j = (j + 1) % m
	for i in arr:
		print(*i, sep='')


t = int(input())
while t:
	t += -1
	(n, m, a, b) = map(int, input().split())
	if m / a != n / b:
		print('NO')
	else:
		print('YES')
		ans = []
		for i in range(n):
			ans.append([0] * m)
		c = 0
		for i in range(n):
			for j in range(a):
				ans[i][c % m] = 1
				c -= -1
		for i in ans:
			print(*i, sep='')


for _ in range(int(input())):
	(m, n, a, b) = map(int, input().split())
	if n * b != m * a:
		print('NO')
	else:
		print('YES')
		p = '1' * a + '0' * (n - a)
		for i in range(m):
			print(p)
			p = ''.join((p[i] for i in range(n - a, n))) + ''.join((p[i] for i in range(n - a)))


from math import gcd

def check(n, m, a, b):
	if m / n == a / b:
		return gcd(m, n)
	return 0

def draw_matrix(n, m, a, b):
	gcd = check(n, m, a, b)
	if not gcd:
		return False
	(x_kecil, y_kecil) = (m // gcd, n // gcd)
	factor = a // x_kecil
	matrix = [[0 for x in range(m)] for y in range(n)]
	for i in range(factor):
		pindah(matrix, i * x_kecil, 0, x_kecil, y_kecil, gcd)
	return matrix

def kotak_kecil(matrix, mulai_x, mulai_y, x_kecil, y_kecil):
	for y in range(y_kecil):
		for x in range(x_kecil):
			if matrix[mulai_y + y][mulai_x + x] == 1:
				assert False
			matrix[mulai_y + y][mulai_x + x] = 1

def pindah(matrix, mulai_x, mulai_y, x_kecil, y_kecil, gcd):
	for i in range(gcd):
		kotak_kecil(matrix, (i * x_kecil + mulai_x) % m, i * y_kecil + mulai_y, x_kecil, y_kecil)
t = int(input())
for __ in range(t):
	(n, m, a, b) = map(int, input().split())
	matrix = draw_matrix(n, m, a, b)
	if not matrix:
		print('NO')
		continue
	print('YES')
	for row in matrix:
		print(''.join(map(str, row)))


from sys import stdin, stdout
import sys
from math import *
input = stdin.readline
for __ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		t = '1' * a + '0' * (m - a)
		for i in range(n):
			print(t)
			t = t[m - a:] + t[:m - a]


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if a * n != b * m:
		print('NO')
		continue
	print('YES')
	flag = 0
	j = 0
	for i in range(n):
		flag = a
		L = [0] * m
		while flag > 0:
			L[j % m] = 1
			flag -= 1
			j += 1
		for d in L:
			print(d, end='')
		print()


cin = lambda : int(input())
mi = lambda : map(int, input().split())
for _ in range(cin()):
	(n, m, a, b) = mi()
	if n * a != m * b:
		print('no')
	else:
		print('yes')
		nz = m - a
		s = '0' * nz + '1' * a
		s = s * (n + 1)
		i = -(m + 1)
		for j in range(n):
			print(s[i:i + m])
			i -= nz


from sys import stdin, stdout

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

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(n, m, a, b) = list(map(int, stdin.readline().split()))
		if n * a != m * b:
			stdout.write('NO\n')
			continue
		stdout.write('YES\n')
		arr = []
		g = gcd(max(n, m), min(n, m))
		g = int(m / g)
		pos = 0
		for i in range(n):
			s = ''
			mn = pos
			mx = (pos + m - a) % m
			for j in range(m):
				if mn <= mx:
					if mn <= j < mx:
						s += '0'
					else:
						s += '1'
				elif mn > mx:
					if 0 <= j < mx or mn <= j <= m - 1:
						s += '0'
					else:
						s += '1'
			pos = (pos + g) % m
			arr.append(s)
		stdout.write('\n'.join(arr) + '\n')
main()


def main():
	t = int(input())
	for _a in range(t):
		(n, m, a, b) = readIntArr()
		if n * a == m * b:
			print('YES')
			matrix = [[0 for _ in range(m)] for __ in range(n)]
			for d in range(1, m + 1):
				if n * d % m == 0:
					break
			start = 0
			for row in range(n):
				i = start
				for __ in range(a):
					matrix[row][i % m] = 1
					i += 1
				start += d
			multiLineArrayOfArraysPrint(matrix)
		else:
			print('NO')
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([''.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
main()


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1

def cin():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos]
from math import gcd
T = int(cin())
res = []
while T:
	T -= 1
	(n, m, a, b) = [int(cin()) for i in range(4)]
	if n * a != m * b:
		res.append('NO')
		continue
	res.append('YES')
	g = [['0' for j in range(m)] for i in range(n)]
	ma = gcd(m, a)
	nb = gcd(n, b)
	a //= ma
	b //= nb
	m //= ma
	n //= nb
	for i in range(nb):
		for j in range(ma):
			for ii in range(n):
				for jj in range(a):
					g[i * n + ii][j * m + (ii + jj) % m] = '1'
	res.append('\n'.join([''.join(row) for row in g]))
os.write(1, '\n'.join(res).encode())


t = int(input())
for kek in range(t):
	(n, m, a, b) = map(int, input().split())
	mat = [[0 for i in range(m)] for i in range(n)]
	if n * a != m * b:
		print('NO')
		continue
	x = a
	i = 0
	j = 0
	while i < n:
		j = j % m
		if x > 0:
			x -= 1
			mat[i][j] = 1
			j += 1
		else:
			x = a
			i += 1
	print('YES')
	for i in mat:
		print(*i, sep='')


def main():
	for __ in [0] * int(input()):
		(n, m, a, b) = map(int, input().split())
		if n * a != m * b:
			print('NO')
			continue
		print('YES')
		k = m // a
		cnt = 0
		for i in range(n):
			if cnt + a > m:
				ans = '1' * ((cnt + a) % m) + '0' * (m - a) + '1' * (m - cnt)
			else:
				ans = '0' * cnt + '1' * a + '0' * (m - cnt - a)
			cnt = (cnt + a) % m
			print(ans)
main()


T = int(input())
for t in range(T):
	(n, m, a, b) = [int(i) for i in input().split()]
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		start = 0
		end = a - 1
		for i in range(n):
			if end >= start:
				print('0' * start + '1' * a + '0' * (m - start - a))
			else:
				print('1' * (end + 1) + '0' * (m - a) + '1' * (-end + a - 1))
			start = (end + 1) % m
			end = (end + a) % m


class Solution:

	def __init__(self):
		test = int(input())
		for i in range(0, test):
			(n, m, a, b) = list(map(int, input().split()))
			self.solve(n, m, a, b)

	def solve(self, n, m, a, b):
		if a * n != b * m:
			return print('NO')
		p = [['1' if col < a else '0' for col in range(0, m)] for row in range(0, n)]
		pos = [(i, j) for j in range(0, a) for i in range(0, n)]
		for j in reversed(range(0, m)):
			for i in range(0, b):
				if not pos:
					return print('NO')
				v = pos.pop()
				if v[1] > j:
					return print('NO')
				temp = p[v[0]][j]
				p[v[0]][j] = p[v[0]][v[1]]
				p[v[0]][v[1]] = temp
		print('YES')
		for row in p:
			print(''.join(row))
Solution()


from sys import stdin
input = iter(stdin.readlines()).__next__

class wlist(list):

	def __setitem__(self, key, value):
		return super().__setitem__(key % len(self), value)
t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a == m * b:
		print('YES')
		mat = [wlist([0 for _ in range(m)]) for _ in range(n)]
		i = 0
		for ri in range(n):
			for ci in range(i, i + a):
				mat[ri][ci] = 1
			i += a
			print(*mat[ri], sep='')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, r, c) = map(int, input().split())
	start = 0
	end = m
	if r / c == m / n:
		print('YES')
		for i in range(n):
			l = [0] * m
			for i in range(r):
				if start == m:
					start = 0
				l[start] = 1
				start += 1
			print(''.join([str(i) for i in l]))
	else:
		print('NO')


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

def main():
	t = int(input())
	for _ in range(t):
		(n, m, a, b) = map(int, input().split())
		if n * a != m * b:
			sys.stdout.write('NO' + '\n')
			continue
		sys.stdout.write('YES' + '\n')
		for i in range(n):
			start = i * a
			Ans = [0] * m
			for j in range(a):
				Ans[(start + j) % m] = 1
			sys.stdout.write(''.join(map(str, Ans)) + '\n')
main()


def nsk(a, b):
	m = a * b
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return m // (a + b)
__ = int(input())
for _ in range(__):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b or b > n or a > m:
		print('NO')
	else:
		print('YES')
		arr = [[0 for i in range(m)] for j in range(n)]
		q = 0
		t = nsk(n, m) // m
		for i in range(m):
			for j in range(q, q + b):
				arr[j % n][i] = 1
			q = q + t
			q = q % n
		for i in arr:
			for j in i:
				print(j, end='')
			print(end='\n')


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rls = lambda : list(map(str, input().split()))

def check(a):
	for i in range(0, r):
		if a[i].count(1) != n:
			return 0
	return 1
t = int(input())
for _ in range(0, t):
	(r, c, n, m) = rl()
	a = []
	col = [0] * c
	for i in range(0, r):
		a.append([0] * c)
	x = 0
	for i in range(0, r):
		for j in range(x, x + n):
			a[i][j % c] = 1
			col[j % c] += 1
		x = (x + n) % c
	f = 1
	d = col
	for i in range(0, c):
		if d[i] > m:
			f = 0
			break
		else:
			x = m - d[i]
		for j in range(0, r):
			if x == 0:
				break
			if a[j][i] == 0:
				a[j][i] = 1
				x = x - 1
		if x != 0:
			f = 0
			break
	if f and check(a):
		print('YES')
		for i in range(0, r):
			for j in range(0, c):
				print(a[i][j], end='')
			print()
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	(n, m, a, b) = map(int, input().split())
	li = [['0' for i in range(m)] for j in range(n)]
	if a * n != b * m:
		print('NO')
	else:
		print('YES')
		for i in range(n):
			for j in range(a):
				li[i][(i * a + j) % m] = '1'
		for i in range(n):
			print(''.join(li[i]), end='\n')


import os
import sys
from io import BytesIO, IOBase

def solution(n, m, a, b):
	if n * a != b * m:
		write('NO')
		return
	write('YES')
	res = [[0] * m for _ in range(n)]
	try:
		d = next((d for d in range(1, m) if d * n % m == 0))
	except BaseException:
		d = 0
	dx = 0
	for i in range(n):
		for j in range(a):
			res[i][(j + dx) % m] = 1
		dx += d
	for row in res:
		ans = ''.join([str(x) for x in row])
		write(ans)

def main():
	for _ in range(r_int()):
		(n, m, a, b) = r_array()
		solution(n, m, a, b)
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))

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

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

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

def r_int():
	return int(input())
main()


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		z = [['0' for j in range(m)] for i in range(n)]
		k = 0
		i = 0
		j = 0
		while k <= n * a:
			for l in range(a):
				z[i][j] = '1'
				k += 1
				j = (j + 1) % m
			i = (i + 1) % n
		print('YES')
		for i in z:
			print(''.join(i))

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


from sys import stdin, stdout

def ab_matrix(n, m, a, b):
	if a * n != b * m:
		return None
	res = [[0 for j in range(m)] for i in range(n)]
	cur = 0
	for i in range(n):
		for j in range(a):
			res[i][cur] = 1
			cur = (cur + 1) % m
	return res
t = int(stdin.readline())
for i in range(t):
	(n, m, a, b) = list(map(int, stdin.readline().split()))
	res = ab_matrix(n, m, a, b)
	if res is None:
		stdout.write('No' + '\n')
	else:
		stdout.write('Yes' + '\n')
		for r in res:
			for c in r:
				stdout.write(str(c))
			stdout.write('\n')


n = int(input())

def r_s(x, j, n):
	sum = 0
	for i in range(n):
		sum += x[i][j]
	return sum

def o_z(x, j1, j2, n):
	for i in range(n):
		if x[i][j1] == 1 and x[i][j2] == 0:
			return i
for _ in range(n):
	(n, m, a, b) = [int(s) for s in input().split()]
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		x = [[1 if i < a else 0 for i in range(m)] for j in range(n)]
		sums = [n] * a + [0] * (m - a)
		for j1 in range(m):
			sum1 = sums[j1]
			if sum1 > b:
				for t in range(sum1 - b):
					for j2 in range(1, m):
						sum2 = sums[j1 - j2]
						if sum2 < b:
							i1 = o_z(x, j1, j1 - j2, n)
							(x[i1][j1], x[i1][j1 - j2]) = (x[i1][j1 - j2], x[i1][j1])
							(sums[j1], sums[j1 - j2]) = (sums[j1] - 1, sums[j1 - j2] + 1)
							break
		for i in range(n):
			print(*x[i], sep='')


import sys
import math as mt
t = int(input())
for __ in range(t):
	(n, m, a, b) = map(int, input().split())
	arr = [[0] * m for i in range(n)]
	if n * a == m * b:
		print('YES')
		d = 1
		for i in range(1, m):
			if n * i % m == 0:
				d = i
				break
		j = 0
		for i in range(n):
			for i1 in range(a):
				arr[i][(i1 + j) % m] = 1
			j = (j + d) % m
		for i in range(n):
			for j in range(m):
				print(arr[i][j], end='')
			print()
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, a, b) = [int(i) for i in input().split()]
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		for i in range(n):
			s = '1' * a + '0' * (m - a)
			val = a * i % m
			print(s[val:] + s[:val])


t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	if not (n >= b and m >= a):
		print('NO')
	elif n * a != m * b:
		print('NO')
	else:
		print('YES')
		left = 0
		counter = 0
		ans = '0' * left + '1' * a + '0' * (m - left - a)
		for i in range(n):
			print(ans[m - left:] + ans[:m - left])
			left += a
			left %= m


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, sin
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
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(*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, a, b) = sp()
	answer = [[0] * m for i in range(n)]
	temp = 0
	for i in range(1, m):
		if i * n % m == 0:
			temp = i
			break
	shift = 0
	for i in range(n):
		for j in range(a):
			answer[i][(j + shift) % m] = 1
		shift += temp
	r = True
	for i in range(m):
		cnt = 0
		for j in range(n):
			cnt += answer[j][i]
		if cnt != b:
			r = False
			break
	if not r:
		out('NO')
		continue
	out('YES')
	for i in answer:
		out(''.join(map(str, i)))


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, m, a, b) = [int(c) for c in input().split()]
	ans = [[0 for i in range(m)] for j in range(n)]
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		colsums = [0 for i in range(m)]
		for i in range(n):
			for j in range(a):
				minindex = colsums.index(min(colsums))
				ans[i][minindex] = 1
				colsums[minindex] += 1
		for i in ans:
			print(''.join([str(x) for x in i]))


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

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

def L():
	return list(NM())

def LN(n):
	return [N() for i in range(n)]

def LL(n):
	return [L() for i in range(n)]
t = N()
from math import gcd

def f():
	(n, m, a, b) = NM()
	if n * a != m * b:
		print('NO')
		return
	print('YES')
	ans = [[0] * m for i in range(n)]
	t = 0
	for i in range(n):
		for j in range(a):
			ans[i][(j + t) % m] = 1
		t += a
	for i in ans:
		print(''.join(map(str, i)))
for i in range(t):
	f()


t = int(input())
for i in range(t):
	(n, m, a, b) = map(int, input().split())
	lst = []
	for i in range(n):
		arr = []
		for j in range(m):
			arr += [0]
		lst += [arr]
	(j, k) = (0, 0)
	x = 0
	while j < n:
		while k < m:
			if x == a:
				x = 0
			while x < a:
				if k < m:
					lst[j][k] = 1
					k += 1
				else:
					break
				x += 1
			if x == a:
				j += 1
			if j >= n:
				break
		k = 0
	flag = 0
	for c in range(m):
		count = 0
		for d in range(n):
			if lst[d][c] == 1:
				count += 1
		if count != b:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')
		for c in range(n):
			for d in range(m):
				print(lst[c][d], end='')
			print()


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	real_result = False
	real_answer = None
	for jump in range(51):
		data = [[0] * m for i in range(n)]
		col_count = [0] * m
		row_count = [0] * n
		result = True
		temp = 0
		for i in range(n):
			now_row = 0
			for j in range(temp, m + temp):
				if col_count[j % m] == b:
					continue
				else:
					data[i][j % m] = 1
					col_count[j % m] += 1
					row_count[i] += 1
					now_row += 1
					if now_row == a:
						break
			if now_row != a:
				result = False
				break
			temp += jump
		if result:
			temp = True
			for i in range(m):
				if col_count[i] != b:
					temp = False
			for i in range(n):
				if row_count[i] != a:
					temp = False
			if temp:
				real_result = True
				real_answer = data
				break
			else:
				pass
	if real_result:
		print('YES')
		for i in range(n):
			for j in range(m):
				print(data[i][j], end='')
			print()
	else:
		print('NO')


def find_matrix():
	(n, m, a, b) = list(map(int, input().split()))
	if n * a != m * b:
		return 'NO'
	matrix = []
	matrix_in = []
	for i in range(m):
		matrix_in.append(1)
	for i in range(n):
		matris = matrix_in.copy()
		matrix.append(matris)
	zero = m - a
	start = 0
	end = zero
	for i in range(n):
		for j in range(start, end):
			j %= m
			matrix[i][j] = 0
		start += zero
		end += zero
	out_return = 'YES'
	for i in matrix:
		out = ''
		for j in i:
			out += str(j)
		out_return += '\n' + out
	return out_return
t = int(input())
output = []
for i in range(t):
	output.append(find_matrix())
for i in output:
	print(i)


for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if a * n != b * m:
		print('NO')
		continue
	g = [[0] * m for _ in range(n)]
	cur = 0
	for i in range(n):
		for _ in range(a):
			g[i][cur] = 1
			cur = (cur + 1) % m
	print('YES')
	for row in g:
		print(*row, sep='')


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
for _ in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a == m * b:
		print('YES')
		l = [['0' for i in range(m)] for i in range(n)]
		t = 0
		for i in range(n):
			for j in range(a):
				l[i][t % m] = '1'
				t += 1
		for i in range(n):
			print(''.join(l[i]))
	else:
		print('NO')


def shift(s, mult):
	s = [s[(i + mult) % len(s)] for i in range(len(s))]
	return s

def solve(n, m, a, b):
	if not a * n == m * b:
		print('NO')
		return None
	print('YES')
	ans = ['1'] * a + ['0'] * (m - a)
	print(''.join(ans))
	for i in range(n - 1):
		ans = shift(ans, a)
		print(''.join(ans))
	return None
n = int(input())
for i in range(n):
	(n, m, a, b) = tuple(map(int, input().split()))
	solve(n, m, a, b)


from math import inf

def solve():
	(n, m, a, b) = map(int, input().split())
	grid = [[0] * m for i in range(n)]
	(row_cnt, col_cnt) = ([0] * n, [0] * m)
	for i in range(n):
		for cnt in range(a):
			mini = inf
			ind = None
			for j in range(m):
				if col_cnt[j] < mini:
					mini = col_cnt[j]
					ind = j
			grid[i][ind] = 1
			row_cnt[i] += 1
			col_cnt[ind] += 1
	if all((r == a for r in row_cnt)) and all((c == b for c in col_cnt)):
		print('YES')
		for row in grid:
			print(''.join(list(map(str, row))))
	else:
		print('NO')

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


import heapq

def solve(n, m, a, b):
	if n * a != m * b or a > m or b > n:
		return (False, None)
	ans = [['1' for _ in range(a)] + ['0' for _ in range(m - a)]]
	count = {}
	for (i, v) in enumerate(ans[0]):
		count[i] = int(v == '1')
	for i in range(n - 1):
		pq = []
		pre = ans[-1]
		for idx in range(m):
			heapq.heappush(pq, (count[idx], idx))
		nxt_ans = ['0' for _ in range(m)]
		count_1 = a
		while pq:
			(c, idx) = heapq.heappop(pq)
			if count_1 >= 1:
				nxt_ans[idx] = '1'
				count[idx] += 1
				if count[idx] > b:
					return (False, None)
				count_1 -= 1
			else:
				break
		ans.append(nxt_ans)
	ans = [''.join(n) for n in ans]
	return (True, ans)
t = int(input())
for i in range(t):
	(n, m, a, b) = list(map(int, input().split()))
	(can, ans) = solve(n, m, a, b)
	if not can:
		print('NO')
	else:
		print('YES')
		for n in ans:
			print(n)


from math import gcd
from sys import stdin, stdout
from pprint import pprint
for _ in range(int(stdin.readline())):
	(n, m, a, b) = map(int, stdin.readline().split())
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		d = m // gcd(n, m)
		start = 0
		ans = ['1'] * a + ['0'] * (m - a)
		for i in range(n):
			stdout.write(''.join(ans[start:]))
			stdout.write(''.join(ans[:start]))
			start = (start + d) % m
			stdout.write('\n')


import sys
import string
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(a, b, c, d) = input().split()
	(a, b, c, d) = (int(a), int(b), int(c), int(d))
	if b / c == a / d:
		print('YES')
		counter = 0
		for l in range(a):
			s = ['0'] * b
			for x in range(c):
				s[counter] = '1'
				counter += 1
				counter = counter % b
			print(''.join(s))
	else:
		print('NO')


import sys

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

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

def main():
	for _ in range(II()):
		(n, m, a, b) = MI()
		if n * a != m * b:
			print('NO')
			continue
		ans = [[0] * m for _ in range(n)]
		j = 0
		for i in range(n):
			for _ in range(a):
				ans[i][j] = 1
				j = (j + 1) % m
		print('YES')
		for row in ans:
			print(*row, sep='')
main()


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

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

def arp(arr):
	return ' '.join([str(i) for i in arr])
for _ in range(int(input())):
	(n, m, a, b) = rl()
	if n * a != m * b:
		print('NO')
	else:
		s = '1' * a + '0' * (m - a)
		print('YES')
		for i in range(n):
			print(s)
			s = s[a:] + s[:a]


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(a, b, c, d) = map(int, input().split())
	if a * c != b * d:
		print('NO')
		continue
	print('YES')
	R = [[0] * b for _ in range(a)]
	for v in range(a):
		v *= c
		s = [0] * b
		for i in range(c):
			s[(v + i) % b] = 1
		print(''.join((str(x) for x in s)))


def buildmatrix(L, n, m):
	L = [['0' for i in range(m)] for j in range(n)]
	for i in range(0, n):
		for k in range(a * i, a * i + a):
			L[i][k % m] = '1'
	return L
t = int(input())
for i in range(0, t):
	L = list(map(int, input().split()))
	n = L[0]
	m = L[1]
	a = L[2]
	b = L[3]
	if n * a != m * b:
		print('NO')
	else:
		print('YES')
		N = buildmatrix(L, n, m)
		for i in range(0, n):
			s = ''
			for j in range(0, m):
				s += N[i][j]
			print(s)


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

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

def main():

	def solve():
		(n, m, a, b) = map(int, input().split())
		if n * a != m * b:
			print('NO')
			return
		print('YES')
		for i in range(n):
			grid = ['0'] * m
			for j in range(i * a, (i + 1) * a):
				grid[j % m] = '1'
			print(''.join(grid))
	q = int(input())
	for _ in range(q):
		solve()
main()


t = int(input())
for T in range(t):
	(n, m, a, b) = [int(x) for x in input().split()]
	n1 = n
	l = []
	if a * n != b * m:
		print('NO')
		continue
	s = '1' * a + '0' * (m - a)
	l.append(s)
	while n > 0:
		curr = l[-1]
		nxt = curr[a:] + curr[0:a]
		l.append(nxt)
		n -= 1
	print('YES')
	for i in range(n1):
		print(l[i])


t = int(input())
for i in range(t):
	(n, m, a, b) = map(int, input().split())
	if m / n == a / b:
		print('YES')
		x = ''
		for k in range(a):
			x = x + '1'
		for l in range(m - a):
			x += '0'
		print(x)
		for j in range(n - 1):
			Rfirst = x[0:m - (j + 1) * a % m]
			Rsecond = x[m - (j + 1) * a % m:]
			print(Rsecond + Rfirst)
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, m, a, b) = map(int, input().split())
	if a * n == b * m:
		w = '1' * a + '0' * (m - a)
		print('YES')
		for j in range(n):
			print(w)
			w = w[m - a:] + w[:m - a]
	else:
		print('NO')


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = list(map(int, list(next_line)))
		elif input_format == 5:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enu = enumerate
ter = lambda a, b, c: b if a else c

def mapl(iterable, format=0):
	if format == 0:
		return list(map(int, iterable))
	elif format == 1:
		return list(map(str, iterable))
	elif format == 2:
		return list(map(list, iterable))

def solve():
	(n, m, a, b) = input(1)
	if n * a != m * b:
		out('NO')
		return
	out('YES')
	for i in range(n):
		q = [ter((i * a + j) % m < a, 1, 0) for j in range(m)]
		out(''.join(mapl(q, 1)))
	return
for i in range(input(11)):
	solve()


T = int(input())
for t in range(T):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		matrix = [['0'] * m for i in range(n)]
		for i in range(n):
			for j in range(a):
				matrix[i][(i * a + j) % m] = '1'
		print('YES')
		for i in matrix:
			print(''.join(i))


import queue
import math
t = int(input())
while t:
	line = input().split()
	(n, m, a, b) = (int(line[0]), int(line[1]), int(line[2]), int(line[3]))
	if a * n != b * m:
		print('NO')
	else:
		arr = [i for i in range(b * m)]
		for i in range(n):
			for j in range(a):
				arr[i * a + j] += (i - arr[i * a + j] // m) * m
		ans = [['0' for j in range(m)] for i in range(n)]
		for x in arr:
			ans[x // m][x % m] = '1'
		print('YES')
		for row in ans:
			print(''.join(row))
	t -= 1


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

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

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

def solve(N, M, A, B):
	if N * A != M * B:
		return (False, [])
	d = lcm(N, M) // N
	matrix = [[0 for _ in range(M)] for _ in range(N)]
	cs = 0
	for r in range(N):
		for c in range(cs, min(cs + A, M)):
			matrix[r][c] = 1
		for c in range(0, A - (M - cs)):
			matrix[r][c] = 1
		cs = (cs + d) % M
	return (True, matrix)
T = int(input())
for ti in range(T):
	(N, M, A, B) = map(int, input().split())
	(a, m) = solve(N, M, A, B)
	if not a:
		print('NO')
	else:
		print('YES')
		for row in m:
			print(''.join(map(str, row)))


t = int(input())
while t > 0:
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('No')
	else:
		print('Yes')
		x = '1' * a + '0' * (m - a)
		for i in range(n):
			print(x)
			x = x[m - a:] + x[:m - a]
	t -= 1


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

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

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

def ia_to_s(a):
	return ' '.join([str(s) for s in a])

def solve(n, m, a, b):
	if a * n != b * m:
		print('NO')
		return
	d = 1
	while d < m:
		if d * n % m == 0:
			break
		d += 1
	s = [[0] * m for _ in range(n)]
	for j in range(a):
		s[0][j] = 1
	for i in range(1, n):
		for j in range(a):
			s[i][(j + d * i) % m] = 1
	print('YES')
	for i in range(n):
		print(''.join([str(x) for x in s[i]]))
	return

def main():
	for _ in range(ri()):
		(n, m, a, b) = ria()
		solve(n, m, a, b)
main()


t = int(input())
for i in range(t):
	(n, m, a, b) = map(int, input().split())
	if n * a == m * b:
		print('YES')
		c = []
		for j in range(n):
			p = ['0'] * m
			c.append(p)
		for i in range(n):
			for j in range(a):
				c[i][j] = '1'
		p = 0
		j = 0
		i = a
		q = 0
		while j < a:
			r = 0
			while r < n - b:
				(c[p][i], c[p][j]) = (c[p][j], c[p][i])
				q += 1
				if q == b:
					q = 0
					i += 1
				r += 1
				p += 1
				if p == n:
					p = 0
				if r == n - b:
					break
			j += 1
		for j in c:
			print(''.join(j))
	else:
		print('NO')


from collections import deque

def solve(n, m, a, b):
	if n * a != m * b:
		print('NO')
		return
	print('YES')
	row = [1] * a + [0] * (m - a)
	row = deque(row)
	for _ in range(n):
		print(''.join((str(x) for x in row)))
		row.rotate(a)
	return
for nt in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	solve(n, m, a, b)


import sys
input = sys.stdin.readline

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

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

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

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

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

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

def 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)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

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

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

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, m, a, b) = int_array()
	if n * a == m * b:
		print('YES')
		ans = '1' * a + '0' * (m - a)
		for i in range(n):
			print(ans)
			ans = ans[m - a:] + ans[:m - a]
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	A = [[0] * m for i in range(n)]
	if n * a == m * b or n / m == b / a:
		print('YES')
		k = -1
		for i in range(1, m):
			if i * n % m == 0:
				k = i
				break
		for i in range(n):
			for j in range(k * i, k * i + a):
				A[i][j % m] = 1
		for i in range(n):
			for j in range(m):
				print(A[i][j], end='')
			print()
	else:
		print('NO')


for o in range(int(input())):
	(n, m, a, b) = map(int, input().split())
	if n * a != m * b:
		print('NO')
	else:
		g = []
		x = ['1'] * a + ['0'] * (m - a)
		x *= 2
		for i in range(n):
			g += [x[i * a % m:i * a % m + m]]
		print('YES')
		for i in g:
			print(''.join(i))


for _ in range(int(input())):
	(n, m, a, b) = list(map(int, input().split()))
	arr = [[0] * m for i in range(n)]
	if m / a != n / b:
		print('NO')
	else:
		print('YES')
		j = 0
		for i in range(n):
			for l in range(a):
				arr[i][j] = 1
				j += 1
				if j == m:
					j = 0
		ans = []
		temp = ''
		for i in range(len(arr)):
			for t in range(len(arr[i])):
				temp += str(arr[i][t])
			print(temp)
			temp = ''


import os
import heapq
import sys
import math
from collections import defaultdict
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, m, a, b) = map(int, input().split())
		if a * n != b * m:
			print('NO')
		else:
			matrix = []
			for i in range(n):
				lis = [str(0) for k in range(m)]
				matrix.append(lis)
			c = 0
			for i in range(n):
				sm = 0
				while True:
					if sm == a:
						break
					matrix[i][c] = '1'
					c += 1
					sm += 1
					c %= m
				c %= m
			print('YES')
			for i in range(n):
				print(''.join(matrix[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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = pow(10, 9) + 7

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

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

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

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

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

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

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

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

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

def solve():
	(n, m, a, b) = sep()
	matrix = []
	d = 0
	for i in range(0, n):
		temp = [0] * m
		for j in range(0, a):
			temp[(j + d) % m] = 1
		d = (d + a) % m
		matrix.append(temp)
	if a * n != b * m:
		print('NO')
	else:
		print('YES')
		for i in range(0, n):
			lol = ''
			for j in range(0, m):
				lol += str(matrix[i][j])
			print(lol)
testcase(int(inp()))


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline
	for _ in range(int(input())):
		(H, W, a, b) = map(int, input().split())
		if H * a != W * b:
			print('NO')
			continue
		print('YES')
		ans = [[0] * W for _ in range(H)]
		for h in range(H):
			for w in range(W):
				if (h * a + w) % W < a:
					ans[h][w] = 1
		for h in range(H):
			print(''.join(map(str, ans[h])))
main()


def solve(r, c, a, b):
	if r * a != c * b:
		print('NO')
	else:
		print('YES')
		temp = '1' * a + '0' * (c - a)
		columns = [int(t) for t in temp]
		print(temp)
		for _ in range(1, r):
			temp = temp[c - a:] + temp[:c - a]
			print(temp)
for _ in range(int(input())):
	(r, c, a, b) = map(int, input().split())
	solve(r, c, a, b)