#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
  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";
    vector<vector<bool>> ans(n, vector<bool>(m, 0));
    int d;
    for (int i = 1; i < m; i++) {
      if ((n * i) % m == 0) d = i;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < a; j++) {
        ans[i][(i * d + j) % m] = 1;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << ans[i][j];
      }
      cout << "\n";
    }
  }
}
