#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Woverflow"
using namespace std;
const short INF16 = ~(1 << 15);
const int INF32 = 1e9;
const int SZ = (1 << 21);
const int SZ2 = 200;
const long long mod = 998244353;
const long long INF64 = 8e18;
const long long P = 53;
const long double eps = 1e-10;
const long double PI = acosl(-1);
inline long long MOD(long long x) {
  x %= mod, x += mod;
  return x % mod;
}
inline long long MOD(long long x, long long m) {
  x %= m, x += m;
  return x % m;
}
inline long long T(long long x) { return x * (x + 1) >> 1; }
long long fpow(long long a, long long b) {
  if (!b) return 1;
  if (b == 1) return a;
  if (b & 1) return fpow(a, b ^ 1) * a % mod;
  long long d = fpow(a, b >> 1);
  return d * d % mod;
}
void Solve(int num_test) {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  if (n * a != m * b) {
    cout << "NO" << endl;
    return;
  }
  vector<vector<char>> was(n, vector<char>(m));
  vector<int> cnt(m);
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < n; j++) was[j][i] = 1;
    cnt[i] = n;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (!was[j][i]) continue;
      if (cnt[i] <= b) break;
      for (int k = i + 1; k < m; k++)
        if (!was[j][k]) {
          was[j][k] = 1;
          was[j][i] = 0;
          cnt[i]--;
          cnt[k]++;
          break;
        }
    }
  }
  cout << "YES" << endl;
  for (auto &i : was) {
    for (int j : i) cout << j;
    cout << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  srand(time(NULL));
  int test = 1;
  cin >> test;
  for (int i = 1; i <= test; i++) Solve(i);
}
