#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 10;
const double inf = 1000;
const int mod = 1000000007;
long long _pow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
int mpt[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    if (n * a != b * m) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    memset(mpt, 0, sizeof(mpt));
    int x = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < a; j++) {
        mpt[i][x++] = 1;
        x %= m;
      }
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        j != m - 1 ? cout << mpt[i][j] : cout << mpt[i][j] << endl;
  }
  return 0;
}
