#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
const long long int INF = 1e9;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long int n, m, a, b;
    cin >> n >> m >> a >> b;
    if (n * a != m * b) {
      cout << "NO" << '\n';
      continue;
    }
    vector<vector<long long int>> ans(n, vector<long long int>(m, 0));
    vector<long long int> prot(m, b);
    long long int maxi = b;
    for (long long int i = 0; i <= n - 1; i++) {
      long long int ones = 0;
      for (long long int j = 0; j <= m - 1; j++) {
        if (prot[j] == maxi) {
          ans[i][j] = 1;
          ones++;
          prot[j]--;
          if (j == m - 1) {
            maxi--;
            if (ones != a) {
              j = -1;
            }
          }
        }
        if (ones == a) break;
      }
    }
    bool check = true;
    for (long long int i = 0; i <= m - 1; i++) {
      if (prot[i] != 0) {
        check = false;
        break;
      }
    }
    if (check) {
      cout << "YES" << '\n';
      for (long long int i = 0; i <= n - 1; i++) {
        for (long long int j = 0; j <= m - 1; j++) cout << ans[i][j];
        cout << '\n';
      }
    } else
      cout << "NO" << '\n';
  }
  return 0;
}
