#include <bits/stdc++.h>
int main() {
int t, n, m;
std::cin >> t;
for (int i = 0; i < t; ++i) {
std::cin >> n >> m;
std::vector<int> res(n * m + 1);
if (n * m == 1) {
std::cout << "1\n";
} else if (n * m <= 3 || (n == 2 && m == 2)) {
std::cout << "NO\n";
} else {
for (int x = 2, s = 0; s <= n + m - 2; ++s) {
for (int j = 0; j < std::max(n, m); ++j) {
for (int k = 0; k < std::min(n, m); ++k) {
if (j + k == s) {
res[n == std::max(n, m) ? j * m + k : k * m + j] = x;
x = (x + 2 > n * m ? 1 : x + 2);
}
}
}
}
std::cout << "YES\n";
for (int n_ = 0; n_ < n; ++n_) {
for (int m_ = 0; m_ < m; ++m_) {
std::cout << res[n_ * m + m_] << " \n"[m_ == m - 1];
}
}
}
}
}