#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i = 0, j = 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0,
               y = 0, z = 0, c, p;
  cin >> c;
  while (c--) {
    cin >> n >> m >> a >> b;
    if (a * n != b * m) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    int arr[n][m];
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        arr[i][j] = 0;
      }
    }
    x = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < a; j++) {
        arr[i][x % m] = 1;
        x++;
      }
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        cout << arr[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
