#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int mxN = 101;
vector<int> shirts[mxN];
struct p {
  int sum, pos;
  bool operator<(p p1) const {
    if (sum != p1.sum) {
      return sum < p1.sum;
    } else {
      return pos < p1.pos;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    if (n * a != m * b)
      cout << "NO\n";
    else {
      cout << "YES\n";
      int g[n][m];
      memset(g, 0, sizeof(g));
      multiset<p> row;
      for (int i = 0; i < n; i++) {
        row.insert({0, i});
      }
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < b; j++) {
          auto it = row.begin();
          int index = (*it).pos;
          int sum = (*it).sum;
          g[index][i] = 1;
          sum += 1;
          row.erase(it);
          row.insert({sum, index});
        }
      }
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          cout << g[i][j];
        }
        cout << "\n";
      }
    }
  }
}
