#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int d = 0 ;
bool cheo1[ 30 ] , cheo2[ 30 ] , matrix[ 30 ] [ 30 ] ;
void reset( ) {
for ( int i = 0 ; i < 30 ; i++ ) {
cheo1[ i] = cheo2[ i] = true ;
for ( int j = 0 ; j < 30 ; j++ )
matrix[ i] [ j] = true ;
}
}
void solve( int n, int k, int i) {
if ( i >= k) {
d++ ;
return ;
}
for ( int x = 0 ; x < n; x++ )
for ( int y = 0 ; y < n; y++ )
if ( matrix[ x] [ y] && cheo1[ x + y] && cheo2[ x - y + n] ) {
matrix[ x] [ y] = cheo1[ x + y] = cheo2[ x - y + n] = false ;
solve( n, k, i + 1 ) ;
matrix[ x] [ y] = cheo1[ x + y] = cheo2[ x - y + n] = true ;
}
}
int main( ) {
int t, n, k;
cin >> t;
for ( int i = 0 ; i < t; i++ ) {
cin >> n>> k;
d = 0 ;
reset( ) ;
solve( n, k, 0 ) ;
cout << "Ban co " << n<< " x " << n<< " co " << d<< " cach dat " << n<< " quan tuong." << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDx2ZWN0b3I+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IGQgPSAwOwoKYm9vbCBjaGVvMVszMF0sIGNoZW8yWzMwXSwgbWF0cml4WzMwXVszMF07Cgp2b2lkIHJlc2V0KCkgewogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAzMDsgaSsrKSB7CiAgICAgICAgY2hlbzFbaV0gPSBjaGVvMltpXSA9IHRydWU7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCAzMDsgaisrKSAKICAgICAgICAgICAgbWF0cml4W2ldW2pdID0gdHJ1ZTsKICAgIH0KfQp2b2lkIHNvbHZlKGludCBuLCBpbnQgaywgaW50IGkpIHsKICAgIGlmIChpID49IGspIHsKICAgICAgICBkKys7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgZm9yIChpbnQgeCA9IDA7IHggPCBuOyB4KyspCiAgICAgICAgZm9yIChpbnQgeSA9IDA7IHkgPCBuOyB5KyspCiAgICAgICAgICAgIGlmIChtYXRyaXhbeF1beV0gJiYgY2hlbzFbeCArIHldICYmIGNoZW8yW3ggLSB5ICsgbl0pIHsKICAgICAgICAgICAgICAgIG1hdHJpeFt4XVt5XSA9IGNoZW8xW3ggKyB5XSA9IGNoZW8yW3ggLSB5ICsgbl0gPSBmYWxzZTsKICAgICAgICAgICAgICAgIHNvbHZlKG4sIGssIGkgKyAxKTsKICAgICAgICAgICAgICAgIG1hdHJpeFt4XVt5XSA9IGNoZW8xW3ggKyB5XSA9IGNoZW8yW3ggLSB5ICsgbl0gPSB0cnVlOwogICAgICAgICAgICB9Cn0KaW50IG1haW4oKSB7CiAgICBpbnQgdCwgbiwgazsKICAgIGNpbj4+IHQ7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IHQ7IGkrKykgewogICAgICAgIGNpbj4+IG4+PiBrOwogICAgICAgIGQgPSAwOwogICAgICAgIHJlc2V0KCk7CiAgICAgICAgc29sdmUobiwgaywgMCk7CiAgICAgICAgCiAgICAgICAJY291dDw8ICJCYW4gY28gIjw8IG48PCAiIHggIjw8IG48PCAiIGNvICI8PCBkPDwgIiBjYWNoIGRhdCAiPDwgbjw8ICIgcXVhbiB0dW9uZy4iPDwgZW5kbDsKICAgIH0KfQ==