#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int t, n, m, a, b;
  for (cin >> t; t; t--) {
    cin >> n >> m >> a >> b;
    if (a * n == b * m) {
      cout << "YES\n";
      pair<int, int> c[m];
      for (int i = 0; i < m; i++) c[i] = {0, i};
      while (n--) {
        string row(m, '0');
        sort(c, c + m);
        for (int i = 0; i < a; c[i++].first++) row[c[i].second] = '1';
        cout << row << endl;
      }
    } else {
      cout << "NO\n";
    }
  }
}
