#include <bits/stdc++.h>
using namespace std;
void hertz() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  hertz();
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, a, b;
    cin >> n >> m >> a >> b;
    if (n * a != m * b) {
      cout << "NO"
           << "\n";
      continue;
    }
    cout << "YES"
         << "\n";
    long long arr[n][m];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        arr[i][j] = 0;
      }
    }
    long long k = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < a; ++j) {
        arr[i][k] = 1;
        k++;
        k %= m;
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        cout << arr[i][j];
      }
      cout << "\n";
    }
  }
}
