#include <bits/stdc++.h>
using namespace std;
const long long int N = 55;
long long int n, m, a, b;
long long int p[N][N];
void solve() {
  memset(p, 0, sizeof(p));
  cin >> n >> m >> a >> b;
  if ((double)n / m != (double)b / a) {
    cout << "NO" << '\n';
    return;
  } else {
    long long int cur = 0;
    for (long long int i = 0; i < n; i++) {
      long long int cnt = a;
      while (cnt > 0) {
        p[i][cur] = 1;
        cur++;
        cur %= m;
        cnt--;
      }
    }
    cout << "YES" << '\n';
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        cout << p[i][j];
      }
      cout << '\n';
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
