#include <bits/stdc++.h>
using namespace std;
long long MPOW(long long x, long long y) {
  if (y == 0) return (long long)1;
  long long ret = MPOW(x, y / 2);
  ret *= ret;
  ret %= 1000000007;
  if (y & 1) ret *= x;
  return ret % 1000000007;
}
long long inv(long long x) { return MPOW(x, 1000000007 - 2); }
int main() {
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(10);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t-- > 0) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    if (n * a != m * b) {
      cout << "NO\n";
      continue;
    }
    vector<vector<bool>> ans(n, vector<bool>(m, 0));
    vector<pair<int, int>> cols;
    for (int j = 0; j < m; j++) cols.push_back({0, j});
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < a; j++) {
        ans[i][cols[j].second] = 1;
        cols[j].first++;
      }
      sort(cols.begin(), cols.end());
    }
    cout << "YES\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cout << ((ans[i][j]) ? "1" : "0");
      cout << "\n";
    }
  }
  return 0;
}
