#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int n, m, a, b, T;
int g[N][N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  scanf("%d", &T);
  while (T--) {
    memset(g, 0, sizeof g);
    scanf("%d%d%d%d", &n, &m, &a, &b);
    if (a * n != b * m) {
      puts("NO");
      continue;
    }
    int t = 0;
    for (int i = 0; i < n; i++) {
      int num = 0;
      for (int j = 0; j < m; j++) {
        if (num < a) {
          g[i][(j + t) % m] = 1;
          num++;
        } else
          break;
      }
      t += gcd(m, a);
    }
    puts("YES");
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) printf("%d", g[i][j]);
      puts("");
    }
  }
  return 0;
}
