#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t-- > 0) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    int s[n][m];
    int p = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) s[i][j] = 0;
    }
    for (int i = 0; i < n; i++) {
      for (int k = 0; k < a; k++) {
        s[i][p] = 1;
        p = (p + 1) % m;
      }
    }
    string ans = "YES";
    for (int i = 0; i < n; i++) {
      int c = 0;
      for (int j = 0; j < m; j++) {
        if (s[i][j]) c++;
      }
      if (c != a) {
        ans = "NO";
        break;
      }
    }
    if (ans == "NO") {
      cout << ans << endl;
      continue;
    }
    for (int i = 0; i < m; i++) {
      int c = 0;
      for (int j = 0; j < n; j++) {
        if (s[j][i]) c++;
      }
      if (c != b) {
        ans = "NO";
        break;
      }
    }
    if (ans == "NO") {
      cout << ans << endl;
      continue;
    } else {
      cout << ans << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cout << s[i][j];
        cout << endl;
      }
    }
  }
  return 0;
}
