#include <bits/stdc++.h>
using namespace std;
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
void _(long long& a, long long b) {
  a = (a % 1000000007 + b % 1000000007) % 1000000007;
  a = (a + 1000000007) % 1000000007;
}
long long cl(long long a, long long b) { return (a / b) + (!(!(a % b))); }
void solve() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  if ((n * a) != (m * b)) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  long long ans[n][m];
  long long i = 0;
  memset(ans, 0, sizeof(ans));
  for (long long j = 0; j < m; ++j) {
    for (long long u = 0; u < b; ++u) {
      ans[i][j] = 1;
      i++;
      i %= n;
    }
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      cout << ans[i][j];
    }
    cout << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
