LiGaYb @ 2024-11-03 19:00:34
#include <iostream>
using namespace std;
const int maxn = 1e3 + 10;
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
char a[maxn][maxn];
bool vis[maxn][maxn];
int n, m, k, x_0, y_0, d_0;
int dfs(int x, int y, int d, int s) {
if (s == 0) {
int cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (vis[i][j] == true) cnt++;
}
}
return cnt;
}
vis[x][y] = true;
int nx = x + dx[d], ny = y + dy[d];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= n && a[nx][ny] == '.')
dfs(nx, ny, d, s - 1);
else dfs(x, y, (d + 1) % 4, s - 1);
}
void doit() {
cin >> n >> m >> k;
cin >> x_0 >> y_0 >> d_0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
int ans = dfs(x_0, y_0, d_0, k);
cout << ans << endl;
return ;
}
int main() {
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
doit();
}
return 0;
}