#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int gcd(int A, int B) {
  if (!B) return A;
  return gcd(B, A % B);
}
int main() {
  int t, n, m, a, b;
  cin >> t;
  while (t--) {
    cin >> n >> m >> a >> b;
    if (a * n != b * m) {
      cout << "NO" << '\n';
      continue;
    }
    vector<string> s(100, string(100, '0'));
    int d = m / gcd(n, m);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = cnt; j < cnt + a; j++) {
        s[i][j % m] = '1';
      }
      cnt += d;
      cnt %= m;
    }
    cout << "YES" << '\n';
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cout << s[i][j];
      cout << '\n';
    }
  }
}
