#include<iostream>usingnamespace std;constint N =20;int n, m, x, y, cnt;int tx[8]={-2,-1,1,2,2,1,-2,-1};int ty[8]={-1,-2,-2,-1,1,2,1,2};bool st[N][N];voiddfs(int x,int y,int t){if(t == m * n){
cnt++;return;}
st[x][y]=true;for(int i =0; i <8; i++){int dx = x + tx[i], dy = y + ty[i];if(dx <0|| dx >= n || dy <0|| dy >= m || st[dx][dy])continue;dfs(dx, dy, t +1);}
st[x][y]=false;}intmain(){int T;scanf("%d",&T);while(T--){
cnt =0;scanf("%d%d%d%d",&n,&m,&x,&y);dfs(x, y,1);printf("%d\n", cnt);}return0;}
#include<bits/stdc++.h>usingnamespace std;constint N =20;int n;int a[N][2], MIN =1e9;voiddfs(int k,int x,int y){if(x && y &&abs(x - y)< MIN) MIN =abs(x - y);if(k >= n)return;for(int i =0; i <2;++i){if(i)dfs(k +1, x * a[k][0], y + a[k][1]);elsedfs(k +1, x, y);}}intmain(){
cin >> n;for(int i =0; i < n;++i) cin >> a[i][0]>> a[i][1];dfs(0,1,0);
cout << MIN <<"\n";return0;}
#include<bits/stdc++.h>usingnamespace std;constint N =55;char s[N][N];int w, h, st[N][N], cnt;int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};voiddfs(int x,int y){++cnt;for(int i =0; i <4;++i){int xx = x + dx[i];int yy = y + dy[i];if(xx >=0&& xx < w && yy >=0&& yy < h &&!st[xx][yy]&& s[xx][yy]=='.'){
st[xx][yy]=1;dfs(xx, yy);}}}intmain(){int x, y;
cin >> h >> w;for(int i =0; i < w;++i){for(int j =0; j < h;++j){scanf(" %c",&s[i][j]);if(s[i][j]=='@'){
x = i;
y = j;}}}dfs(x, y);
cout << cnt <<"\n";return0;}