#include <bits/stdc++.h>
using namespace std;
int typetest;
inline void fastIOfileinput() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  typetest = 1;
}
const int N = 50 + 2;
int m, n, a, b;
int ans[N][N];
void Enter() {
  cin >> m >> n >> a >> b;
  memset(ans, 0, sizeof(ans));
}
void solve() {
  if (a * m != b * n) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  int nw = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= a; j++) {
      nw++;
      nw %= n;
      if (nw == 0) nw = n;
      ans[i][nw] = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) cout << ans[i][j];
    cout << '\n';
  }
}
int main() {
  fastIOfileinput();
  if (typetest) {
    int t;
    cin >> t;
    while (t--) {
      Enter();
      solve();
    }
  } else {
    Enter();
    solve();
  }
}
