#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m, a, b;
    cin >> n >> m >> a >> b;
    long long int arr[n + 5][m + 5];
    long long int i, j;
    memset(arr, 0, sizeof(arr));
    for (i = 0; i < n; i++) {
      long long int x = a;
      for (j = m - 1; j >= 0; j--) {
        if (x > 0) {
          arr[i][j] = 1;
          x--;
        } else {
          break;
        }
      }
    }
    long long int flag = 0;
    for (j = 0; j < m; j++) {
      long long int count = 0;
      for (i = 0; i < n; i++) {
        if (arr[i][j] == 1) {
          count++;
        }
      }
      if (count > b) {
        flag = 1;
        break;
      }
      long long int y = count;
      while (y < b) {
        for (i = 0; i < n; i++) {
          if (arr[i][j] == 0) {
            for (int h = j + 1; h < m; h++) {
              if (arr[i][h] == 1) {
                arr[i][h] = 0;
                arr[i][j] = 1;
                y++;
                break;
              }
            }
          }
          if (y == b || i == n - 1) {
            break;
          }
        }
        if (y == b || i == n - 1) {
          break;
        }
      }
      if (y != b) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          cout << arr[i][j];
        }
        cout << endl;
      }
    }
  }
}
