#include <bits/stdc++.h>
using namespace std;
int t, n, m, a, b;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d %d", &n, &m, &a, &b);
    int dp[n][m];
    memset(dp, 0, sizeof(dp));
    if (m * b == n * a) {
      printf("YES\n");
      int d;
      for (int i = 1; i <= a; i++) {
        if ((i * n) % m == 0) {
          d = i;
          break;
        }
      }
      int roffset = 0;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < a; j++) dp[i][(j + roffset) % m] = 1;
        roffset += d;
      }
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) printf("%d", dp[i][j]);
        printf("\n");
      }
    } else
      printf("NO\n");
  }
  return 0;
}
