#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b, i, j = 0, cnt;
    cin >> n >> m >> a >> b;
    int arr[n][m];
    if (m * b == n * a) {
      cout << "YES" << endl;
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          arr[i][j] = 0;
        }
      }
      j = 0;
      for (i = 0; i < n; i++) {
        cnt = 0;
        while (cnt < a) {
          if (j >= m) {
            j = j % m;
          }
          arr[i][j] = 1;
          cnt++;
          j++;
        }
      }
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          cout << arr[i][j];
        }
        if (i == n - 1) {
          continue;
        }
        cout << endl;
      }
      cout << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
