#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (; t > 0; t--) {
    int n, m, a, b, i, j;
    cin >> n >> m >> a >> b;
    vector<pair<int, int>> v(m);
    for (i = 0; i < m; i++) {
      v[i].first = b;
      v[i].second = i;
    }
    int ans[n][m];
    memset(ans, 0, sizeof(ans));
    bool f = 0;
    for (i = 0; i < n; i++) {
      sort(v.begin(), v.end());
      int x = a;
      for (j = m - 1; j >= 0 && x > 0; j--) {
        if (v[j].first > 0) {
          v[j].first--;
          x--;
          ans[i][v[j].second] = 1;
        }
      }
      if (x > 0) {
        f = 1;
        break;
      }
    }
    for (j = 0; j < m; j++) {
      int cnt = 0;
      for (i = 0; i < n; i++) {
        if (ans[i][j] == 1) cnt++;
      }
      if (cnt != b) {
        f = 1;
        break;
      }
    }
    if (f == 1)
      cout << "NO\n";
    else {
      cout << "YES\n";
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) cout << ans[i][j];
        cout << "\n";
      }
    }
  }
  return 0;
}
