#include <bits/stdc++.h>
using namespace std;
const int Mx = 52;
int A[Mx][Mx];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    if (a * n != b * m) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    for (int i = 0; i < a * n; i++) A[i / a][i % m] = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << A[i][j];
        A[i][j] = 0;
      }
      cout << "\n";
    }
  }
}
