#include <bits/stdc++.h>
using namespace std;
int main() {
  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;
    }
    int i, j;
    int arr[n][m];
    memset(arr, 0, sizeof arr);
    int curr = 0;
    for (i = 0; i < n; i++)
      for (j = 0; j < a; j++) {
        arr[i][curr] = 1;
        curr++;
        curr %= m;
      }
    cout << "YES" << endl;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) cout << arr[i][j];
      cout << endl;
    }
  }
}
