#include <bits/stdc++.h>
using namespace std;
bool check(int n, int m, int a, int b) {
  double x = (double)n / (double)m;
  double y = (double)b / (double)a;
  if (x == y) return true;
  return false;
}
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;
    if (check(n, m, a, b)) {
      cout << "YES\n";
      int arr[n][m];
      memset(arr, 0, sizeof(arr));
      int cnt = 0;
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < b; j++) {
          arr[cnt % n][i] = 1;
          cnt++;
        }
      }
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cout << arr[i][j];
        cout << endl;
      }
    } else {
      cout << "NO\n";
    }
  }
}
