#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long N = 11;
const double pai = 3.14159265358979;
const long long maxn2 = 1e3 + 2;
long long read() {
  long long x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') {
      w = -1;
    }
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return w * x;
}
long long aa[55][55];
int main() {
  long long t = read();
  for (long long h = 1; h <= t; ++h) {
    long long n = read();
    long long m = read();
    long long a = read();
    long long b = read();
    if (n * a != m * b) {
      cout << "NO" << endl;
      continue;
    }
    long long k = n * a;
    for (long long i = 1; i <= n; ++i)
      for (long long j = 1; j <= m; ++j) aa[i][j] = 0;
    long long tmp = 0;
    long long s = 1;
    long long ss = 1;
    while (tmp < k) {
      for (long long i = 1; i <= n; ++i) {
        if (aa[i][s] == 1) {
          s++;
          while (!aa[i][s]) {
            if (aa[i][s] == 0) break;
            s++;
          }
        }
        aa[i][s] = 1;
        tmp++;
        s++;
        if (s > m) s = 1;
      }
    }
    cout << "YES" << endl;
    for (long long i = 1; i <= n; ++i) {
      for (long long j = 1; j <= m; ++j) cout << aa[i][j];
      cout << endl;
    }
  }
  return 0;
}
