#include <stdio.h>
int ans = 0;
int visit[9][9];
void dfs(int i, int j, int cnt, int max_i, int max_j, int max_cnt) {
if (cnt == max_cnt) {
ans += 1;
return;
}
visit[i][j] = 1;
int pos[8][2] = { {i-2, j-1}, {i-2, j+1}, {i+2, j-1}, {i+2, j+1}, {i-1, j-2}, {i-1, j+2}, {i+1, j-2}, {i+1, j+2} };
int ii = 0, jj = 0;
for (auto & po : pos) {
ii = po[0];
jj = po[1];
if (ii >= 0 && ii < max_i && jj >= 0 && jj < max_j && visit[ii][jj] == 0) {
dfs(ii, jj, cnt+1, max_i, max_j, max_cnt);
}
}
visit[i][j] = 0;
}
int main(void) {
int T = 0;
int m, n, si, sj;
scanf("%d", &T);
for (int i = 0; i < T; i++) {
scanf("%d %d %d %d", &m, &n, &si, &sj);
ans = 0;
dfs(si, sj, 1, m, n, m*n);
printf("%d\n", ans);
}
return 0;
}
bfs可能更好