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