#JavaScript (ES6), 160 bytes <!-- language-all: lang-javascript --> n=>(g=(o,v,p)=>[...Array(N=2*n),p+N-1,p+1,p+n].reduce((s,x,i)=>v>>(x=i<N?i:x%N)&1?s:s+g((i>=N)/p?[...o,p<x?p*n*n+x:x*n*n+p]:o,v|1<<x,x),g[o.sort()]^(g[o]=1)))`` [Try it online!](https://tio.run/##XY1BCsIwEEX3nqIbZaaNKakVpDQpXiAXkIql1hKRJCS1RPDutepKFzOf//7w59qMjW@dssNam3M3XfikuYCegyEjscjFgVK6d655gORZrJHYRK7ZvN@ja@q6873tADwJRM33oxAQuCplpYqwlLhilS980gMowSWmtno3GmLLUNlYxzoJRfiorYv56ZOVZSABSX8w1Bs3ANZHmE3NGSKeTlNrtDe3jt5MDxfIEKM0jTb54pdvvjzL2V@QfwO23WXTCw "JavaScript (Node.js) – Try It Online")