#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int t[11][11];
void test(){
int n, m;
cin >> n >> m;
if ((n==1 && m<= 3) || (n <= 3 && m==1) || (n==2 && m==2) ) {
cout << "NO\n";
return;
}
cout << "YES\n";
if (m >= 3) {
int a = 1, b = n*m/2+1;
bool nexta = false;
// The following works if n>=3 and m >= 2.
for (int i=1; i<=n; ++i){
for (int j=1; j<=m; ++j){
if (nexta){
cout << a << " ";
a++;
}
else {
cout << b << " ";
b++;
}
nexta = 1 - nexta;
}
cout << "\n";
}
}
else {
int a = 1, b = n*m/2+1;
bool nexta = false;
// The following works if n>=3 and m >= 2.
for (int j=1; j<=m; ++j){
for (int i=1; i<=n; ++i){
if (nexta){
t[i][j] = a;
a++;
}
else {
t[i][j] = b;
b++;
}
nexta = 1 - nexta;
}
}
for (int i=1; i<=n; ++i){
for (int j=1; j<=m; ++j){
cout << t[i][j] << " ";
}
cout << "\n";
}
}
}
int main(){
int t;
cin >> t;
for (int i=0; i<t; ++i){
test();
}
}