#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, t, d, v;
int ar[51];
void solve() {
  cin >> n >> m >> a >> b;
  if (a * n != m * b)
    cout << "NO\n";
  else {
    cout << "YES\n";
    for (d = 1; d < m and ((d * n) % m) != 0; d++)
      ;
    for (int i = 0; i < a; i++) ar[i] = 1;
    for (int i = a; i < m; i++) ar[i] = 0;
    v = 0;
    for (int i = 0; i < n; i++) {
      for (int j = v, k = 0; k < m; k++, j = (j + 1) % m) cout << ar[j];
      v = (v + d) % m;
      cout << endl;
    }
  }
}
int main() {
  cin >> t;
  while (t--) solve();
  return 0;
}
