#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, a, b;
    cin >> n >> m >> a >> b;
    long long arr[n][m];
    memset(arr, 0, sizeof(arr));
    long long p = 0;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < a; j++) {
        arr[i][p] = 1;
        p = (p + 1) % m;
      }
    }
    long long flag = 0;
    for (long long j = 0; j < m; j++) {
      long long cnt = 0;
      for (long long i = 0; i < n; i++) {
        if (arr[i][j] == 1) cnt++;
      }
      if (cnt != b) {
        flag = 1;
        break;
      }
    }
    if (flag)
      cout << "NO"
           << "\n";
    else {
      cout << "YES"
           << "\n";
      for (long long i = 0; i < n; i++) {
        for (long long j = 0; j < m; j++) cout << arr[i][j];
        cout << "\n";
      }
    }
  }
  return 0;
}
