#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    int total_ones = n * a;
    if (total_ones != m * b) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
      string str = "";
      for (int i = 0; i < m; i++) {
        if (i < a)
          str += '1';
        else
          str += '0';
      }
      for (int i = 0; i < n; i++) {
        cout << str << endl;
        for (int j = 0; j < a; j++) {
          char c = str[0];
          str = str.substr(1);
          str = str + c;
        }
      }
    }
  }
}
