#include <bits/stdc++.h>
using namespace std;
void speed_up() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
signed main() {
  speed_up();
  long long t;
  cin >> t;
  for (long long _ = 0; _ < t; _++) {
    long long n, m, a, b;
    cin >> n >> m >> a >> b;
    if (n * a != m * b) {
      cout << "NO\n";
      continue;
    }
    vector<vector<char> > table(n, vector<char>(m, '0'));
    for (long long i = 0; i < n; i++) {
      for (long long j = i * a; j < (i + 1) * a; j++) {
        table[i][j % m] = '1';
      }
    }
    cout << "YES\n";
    for (auto i : table) {
      for (auto j : i) {
        cout << j;
      }
      cout << "\n";
    }
  }
}
