#include <bits/stdc++.h>
int main() {
  int t;
  int i, j, k;
  int flag;
  int n, m, a, b;
  int ans[55][55];
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d%d", &n, &m, &a, &b);
    flag = 0;
    if (n * a != m * b || (n * a) % m != 0)
      printf("NO\n");
    else {
      printf("YES\n");
      i = 0;
      flag = 0;
      while (i < n) {
        for (j = flag; j < flag + a; j++) {
          ans[i][j % m] = 1;
        }
        i++;
        flag = (flag + a) % m;
      }
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          if (ans[i][j] != 1) ans[i][j] = 0;
          putchar(ans[i][j] + 48);
          ans[i][j] = 0;
        }
        putchar('\n');
      }
    }
  }
  return 0;
}
