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

Difficulty: introductory

Starter code:

Solutions:
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])))

import sys
input = sys.stdin.readline

t=int(input())
for tests in range(t):
    n,m,a,b=list(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)))
                    
                

    
                
    


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

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
# import sys
# input = sys.stdin.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')

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


import sys
max_int = 1000000001  # 10^9+1
min_int = -max_int

t = int(input())
for _t in range(t):
    n, m, a, b = list(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))




import sys
T = int(sys.stdin.readline().strip())

for t in range(T):
    (n, m , a, b) = list(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]))



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


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)


def __starting_point():
    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)

__starting_point()

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 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=list(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 math 
#------------------------------warmup----------------------------
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")
 
#-------------------game starts now----------------------------------------------------
for ik in range(int(input())):
    n,m,a,b=map(int,input().split())
    if a*n!=b*m:
        print("NO")
    else:
        d=0
        print("YES")
        ans=[[0 for i in range(m)]for j in range(n)]
        for i in range(n):
            for j in range(a):
                ans[i][d%m]=1
                d+=1
            print(*ans[i],sep="")
                
            
        

import sys
def input():
    return sys.stdin.readline()[:-1]
def main():
    for _ in range(int(input())):
        n, m, a, b = list(map(int,input().split()))
        if abs(n/b - m/a) > 0.00001:
            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))
def __starting_point():
    main()

__starting_point()

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 sys;input=sys.stdin.readline
T, = list(map(int, input().split()))
for _ in range(T):
    a, b, c, d = list(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))


# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
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()))


# @mt
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)


def __starting_point():
    main()

__starting_point()

import sys
from collections import defaultdict as dd
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
from math import *
import copy
#sys.setrecursionlimit(10**6)
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':
			#print(i,j,"LOL")
			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	
		#print(i,j)		
		#for ppp in d:		
		#	print(*ppp)

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

'''     ##     ##  #######  # #  ######
        ##     ##  ##   ##  ###    ##
        ##     ##  ##    #  # #    ##
        #########  #######  # #    ##    '''

import sys
import math
# sys.setrecursionlimit(10**6)

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(1e9+7); BABYMOD = 998244353;

def __starting_point():
    # sys.stdin = open("input.txt","r")  # <<<  ^o^  Comment this line  ^_^  >>>
    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()
                    
            


# #############################################################################
'''
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
>>> DO NOT PLAGIARISE.
TESTCASES:
'''
__starting_point()

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

import math
t=int(input())
def convert(s): 
  
    # initialization of string to "" 
    new = "" 
  
    # traverse in the string  
    for x in s: 
        new += x  
  
    # return string  
    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)

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


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


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

for _ in range(int(input())):
    n, m, a, b = list(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]


from collections import defaultdict as dd
import math
def nn():
	return int(input())

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

def mi():
	return list(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))