#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int sol[101][101];
void testCase() {
int n,m;
cin >> n >> m;
if (max(n,m) <= 2 || (min(n,m) == 1 && max(n,m) <= 3)) {
cout << "NO\n";
return;
}
cout << "YES\n";
if (min(n,m) == 1) {
int x = max(n,m);
for (int i = 0; i < x/2; i++) {
cout << (i+1)*2;
if (n == 1) cout << " ";
else cout << "\n";
}
for (int i = x/2; i < x; i++) {
cout << (i-x/2)*2 + 1;
if (n == 1) cout << " ";
else cout << "\n";
}
if (n == 1) cout << "\n";
return;
}
int val = 2;
int goal = val * ((n*m)/2);
if (n < m) {
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
sol[i][j] = val;
if (val == goal) val = -1;
val += 2;
}
}
} else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
sol[i][j] = val;
if (val == goal) val = -1;
val += 2;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << sol[i][j] << " ";
}
cout << "\n";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
testCase();
}
}