#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  if (n * a != m * b)
    cout << "NO\n";
  else {
    int arr[n][m];
    memset(arr, 0, sizeof(arr));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < a; j++) {
        arr[i][(i * a + j) % m] = 1;
      }
    }
    cout << "YES\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << arr[i][j];
      }
      cout << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int _t;
  cin >> _t;
  while (_t--) solve();
}
