#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    if (n * a != m * b) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    vector<vector<int> > mat(n, vector<int>(m, 0));
    int i = 0, j;
    int st = 0, en;
    while (i < n) {
      en = (st + a - 1) % m;
      j = st;
      while (j != en) {
        mat[i][j] = 1;
        j = (j + 1) % m;
      }
      mat[i][j] = 1;
      st = (en + 1) % m;
      i++;
    }
    for (int i = 0; i <= n - 1; i++) {
      for (int j = 0; j <= m - 1; j++) {
        cout << mat[i][j];
      }
      cout << '\n';
    }
  }
  return 0;
}
