#include <bits/stdc++.h>
using namespace std;
template <class T, class second>
ostream& operator<<(ostream& s, pair<T, second>& p) {
  s << '{' << p.first << ", " << p.second << '}';
  return s;
}
template <class T>
ostream& operator<<(ostream& s, vector<T>& v) {
  if (v.empty()) {
    s << "[]";
    return s;
  }
  s << '[';
  for (int i = 0; i < v.size() - 1; i++) {
    s << v[i] << ", ";
  }
  s << v.back() << ']';
  return s;
}
int n, m, a, b;
char ans[51][51];
set<pair<int32_t, int32_t> > rs;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    cin >> n >> m >> a >> b;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) ans[i][j] = 0;
    if (n * a != m * b) {
      puts("NO");
      continue;
    }
    rs.clear();
    for (int i = 0; i < n; i++) {
      rs.insert({0, i});
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < b; j++) {
        auto p = *rs.begin();
        rs.erase(rs.begin());
        rs.insert({p.first + 1, p.second});
        ans[p.second][i] = '1';
      }
    }
    puts("YES");
    string a;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) a.push_back(ans[i][j] ? ans[i][j] : '0');
      cout << a << endl;
      a.clear();
    }
  }
  return 0;
}
