#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<int>> build(int h, int w) {
if (h >= 4) {
vector<vector<int>> res(h, vector<int>(w, -1));
for (int x = 0; x < w; ++x) {
for (int y = 0; y < h / 2; ++y) {
res[y][x] = 2*(y + 1) + x * h;
}
for (int y = 0; y < (h + 1) / 2; ++y) {
res[y + h/2][x] = (2*y + 1) + x * h;
}
}
return res;
} else if (h == 3 && w == 2) {
return {{2, 4}, {6, 1}, {3, 5}};
} else if (h == 3 && w == 3) {
return {{2, 6, 4}, {9, 1, 8}, {3, 7, 5}};
}
assert(false);
}
void solve() {
int h, w;
cin >> h >> w;
// 3x1 and 2x2 are impossible, anything larger is possible
if (h + w <= 4) {
cout << "NO" << '\n';
} else {
cout << "YES" << '\n';
if (h >= w) {
auto res = build(h, w);
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
cout << res[y][x] << ' ';
}
cout << '\n';
}
} else {
auto res = build(w, h);
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
cout << res[x][y] << ' ';
}
cout << '\n';
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int ti = 0; ti < t; ++ti) solve();
}