#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n, m;
cin >> n >> m;
if(n * m * (n + 1) * (m + 1) % 8 != 0) {
cout << "No\n";
return ;
}
cout << "Yes\n";
bool horizon = 1;
if(m * (m + 1) % 4 != 0) {
swap(n, m);
horizon = 0;
}
int tar = m * (m + 1) / 4 - m, cur = 0;
vector<int> seg;
while(rem) {
int l = 1, r = m + 1;
while(l < r - 1) {
int mid = l + r >> 1;
if(1ll * cur + mid * (mid + 1) / 2 <= tar)
l = mid;
else
r = mid;
}
seg.emplace_back(l);
rem -= l;
cur += l * (l + 1) / 2;
}
string s;
bool now = 0;
for(auto &c : seg) {
for(int i = 0; i < c; ++i)
s += '0' + now;
now ^= 1;
}
if(horizon) {
for(int i = 0; i < n; ++i) {
for(auto &c : s)
cout << c << ' ';
cout << '\n';
}
} else {
for(auto &c : s) {
for(int i = 0; i < n; ++i)
cout << c << " \n"[i == n - 1];
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
cin >> T;
while(T--)
solve();
return 0;
}