#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 110031;
int tests, n, m, a, b;
int ans[131][131];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> tests;
  for (; tests; --tests) {
    cin >> n >> m >> a >> b;
    if (n * a != m * b) {
      cout << "NO" << endl;
      continue;
    }
    int ptr = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        ans[i - 1][j - 1] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < a; j++) {
        ans[i][ptr] = 1;
        ++ptr;
        ptr %= m;
      }
    }
    cout << "YES" << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << ans[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
