#include <bits/stdc++.h>
using namespace std;
int n, m, t, a, b, ans[100][100];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    bool ok = 0;
    cin >> n >> m >> a >> b;
    if (n * a != m * b) {
      cout << "NO\n";
      continue;
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) ans[i][j] = 0;
    int j = 0;
    for (int x = 0; x < n; x++)
      for (int y = 0; y < a; y++) {
        ans[x][j] = 1;
        j = (j + 1) % m;
      }
    cout << "YES\n";
    for (int i = 0; i < n; i++, cout << endl)
      for (int j = 0; j < m; j++) cout << ans[i][j];
  }
  return 0;
}
