#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 index = 0;
    cout << "YES" << endl;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        cout << ((index + j) % m < a ? 1 : 0);
      }
      index -= a;
      if (index < 0) index += m;
      cout << endl;
    }
  }
  return 0;
}
