#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int mp[N][N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    memset(mp, 0, sizeof(mp));
    cin >> n >> m >> a >> b;
    if (a * n == b * m) {
      int j = 1;
      for (int i = 1; i <= n; i++)
        for (int k = 1; k <= a; k++, j++) {
          if (j == m + 1) j = 1;
          mp[i][j] = 1;
        }
      puts("YES");
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          cout << mp[i][j];
        }
        cout << '\n';
      }
    } else
      puts("NO");
  }
  return 0;
}
