#include <bits/stdc++.h>
using namespace std;
int row[100], col[100];
int e[55][55];
int t, n, m, a, b;
int main() {
  cin >> t;
  while (t--) {
    memset(row, 0, sizeof(row));
    memset(col, 0, sizeof(col));
    memset(e, 0, sizeof(e));
    cin >> n >> m >> a >> b;
    int flag = 1;
    int j = m - 1;
    for (int i = 0; i < n; i++) {
      int uu = a;
      while (uu--) {
        if (col[j] < b) {
          col[j]++;
          row[i]++;
          e[i][j] = 1;
        }
        j--;
        if (j == -1) {
          j = m - 1;
        }
        if (row[i] == a) {
          break;
        }
      }
      if (row[i] != a) {
        flag = 0;
        break;
      }
    }
    for (int j = 0; j < m; j++) {
      if (col[j] != b) {
        flag = 0;
        break;
      }
    }
    if (flag == 0) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << e[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
