#include <iostream>
#include <cstring>
using namespace std;
int res[12][12];
int main() {
int t;cin>>t;
while(t--){
memset(res,0,sizeof(res));
int n,m;cin>>n>>m;
bool s=0;
if (n>m) swap(n,m),s=1;
if (n<=2 && m<=2 || n==1 && m==3) {
cout<<"NO\n";
continue;
}
int c=1;
for(int i=0; i<n; ++i) for(int j=0; j<m; j+=2) res[i][j]=c++;
for(int i=0; i<n; ++i) for(int j=1; j<m; j+=2) res[i][j]=c++;
if (n==2 && m==3) {
const int x[] = {1,5,3};
const int y[] = {4,2,6};
copy(x,x+3,res[0]);
copy(y,y+3,res[1]);
}
cout<<"YES\n";
if (s) {
for(int i=0; i<n; ++i) for(int j=i+1; j<m; ++j) swap(res[i][j],res[j][i]);
swap(n,m);
}
for(int i=0; i<n; ++i) {
for(int j=0; j<m; ++j) cout<<res[i][j]<<' ';
cout<<'\n';
}
}
}