#include <algorithm>
#include <iostream>
#include <optional>
#include <random>
#include <vector>
using namespace std;
optional<vector<int>> ratko(int n, int m) {
mt19937 rng(1237);
if((min(n, m) == 1 && max(n, m) == 3) || max(n, m) == 2) {
return nullopt;
}
vector<int> ret(n * m);
for(int i = 0; i < (int)ret.size(); ++i) {
ret[i] = i + 1;
}
bool ok = false;
while(true) {
shuffle(ret.begin(), ret.end(), rng);
for(int i = 1; i < n; ++i) {
for(int j = 0; j < m; ++j) {
if(abs(ret[m * i + j] - ret[m * (i - 1) + j]) <= 1) {
goto nope;
}
}
}
for(int i = 0; i < n; ++i) {
for(int j = 1; j < m; ++j) {
if(abs(ret[m * i + j] - ret[m * i + (j - 1)]) <= 1) {
goto nope;
}
}
}
ok = true;
break;
nope: {}
}
if(ok) {
return ret;
} else {
return nullopt;
}
}
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
for(int ti = 0; ti < t; ++ti) {
int n, m;
cin >> n >> m;
optional<vector<int>> retOpt = ratko(n, m);
if(retOpt.has_value()) {
vector<int>& ret = retOpt.value();
int p = 0;
cout << "YES\n";
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
cout << ret[p++] << " ";
}
cout << "\n";
}
} else {
cout << "NO\n";
}
}
return 0;
}