#include <bits/stdc++.h>
using namespace std;
int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, -1, 1};
int arr[55][55];
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    if (n * a != m * b) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES\n";
    int c = 0, x = 0;
    for (int i = 0; i < n && c < n * a; ++i) {
      for (int j = 0; j < a && c < n * a; c++, ++j) {
        arr[i][x] = 1;
        x = (x + 1) % m;
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        cout << arr[i][j];
      }
      cout << endl;
    }
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) arr[i][j] = 0;
  }
  return 0;
}
