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