#include <bits/stdc++.h>
int N, M, A, B;
char table[60][60];
int rows[60];
int cols[60];
int solve() {
  scanf("%d%d%d%d", &N, &M, &A, &B);
  if (A * N != B * M) {
    puts("NO");
    return 0;
  }
  memset(table, 0, sizeof(table));
  memset(rows, 0, sizeof(rows));
  memset(cols, 0, sizeof(cols));
  std::vector<std::pair<int, int>> sorted_cols;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      table[i][j] = '0';
    }
    sorted_cols.clear();
    for (int j = 0; j < M; ++j) {
      sorted_cols.push_back(std::make_pair(cols[j], j));
    }
    std::sort(sorted_cols.begin(), sorted_cols.end());
    for (int j = 0; j < A; ++j) {
      int col_index = sorted_cols[j].second;
      int col_value = sorted_cols[j].first;
      if (col_value >= B) {
        puts("NO");
        return 0;
      }
      table[i][col_index] = '1';
      ++rows[i];
      ++cols[col_index];
    }
  }
  puts("YES");
  for (int i = 0; i != N; ++i) {
    puts(table[i]);
  }
  return 0;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
}
