#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long temp;
void solve() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  if (n * a != m * b) {
    cout << "NO" << '\n';
    return;
  }
  long long arr[n][m];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) arr[i][j] = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = (i + 1) * a; j < (i + 2) * a; j++) {
      arr[i][j % m] = 1;
    }
  }
  cout << "YES" << '\n';
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) cout << arr[i][j];
    cout << '\n';
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
