#include <bits/stdc++.h>
using namespace std;
const bool ready = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12);
  return true;
}();
const double PI = acos(-1);
using ll = long long;
using pii = pair<ll, ll>;
using pdd = pair<double, double>;
using vd = vector<double>;
using vb = vector<bool>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
void solve() {
  ll n;
  cin >> n;
  ;
  ll m;
  cin >> m;
  ;
  ll a;
  cin >> a;
  ;
  ll b;
  cin >> b;
  ;
  if (n * a != m * b) {
    cout << "NO" << endl;
    return;
  }
  vvi ans(n, vi(m));
  for (ll i = 0; i < n * m; i++) {
    ll x = 0;
    ll r = i / m;
    if ((i + (r * a)) % m < a) x = 1;
    ans[i / m][i % m] = x;
  }
  cout << "YES" << endl;
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      cout << ans[i][j];
    }
    cout << endl;
  }
}
signed main() {
  ll t;
  cin >> t;
  ;
  while (t--) solve();
}
