// cheese-cracker [2022-02-06]

void solve(){
    long n = scan;
    long k = scan;

    if(k == 1 || (n % 2 == 0)){
        writeln("YES");
    }else{
        writeln("NO");
        return;
    }
    long m = n * k;
    long x = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < k; ++j){
            write(x, " ");
            x += 2;
            if(x > m){
                x = 2;
            }
        }
        writeln;
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
