#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
mt19937 gen(1337);
int check(int n, int m, const vector<int>& perm){
for (int i=0;i<n;i++){
for (int j=0;j<m;j++){
if (i+1<n){
if (abs(perm[i*m+j]-perm[i*m+m+j])<=1) return 0;
}
if (j+1<m){
if (abs(perm[i*m+j]-perm[i*m+j+1])<=1) return 0;
}
}
}
return 1;
}
void solve(){
int n,m;
cin>>n>>m;
vector<int> perm(n*m);
for (int i=0;i<n*m;i++){
perm[i]=i+1;
}
for (int it=0;it<1000;it++){
shuffle(perm.begin(), perm.end(), gen);
if (check(n,m,perm)){
cout<<"YES"<<endl;
for (int i=0;i<n;i++){
for (int j=0;j<m;j++){
cout<<perm[i*m+j]<<" ";
}
cout<<endl;
}
return;
}
}
cout<<"NO"<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
for (int tc=0;tc<t;tc++){
solve();
}
}