MC_dream_tsr @ 2024-11-16 16:18:28
# include<bits/stdc++.h>
# define rep(i, a) for(int i = 1; i <= a; i++)
using namespace std;
int n, m, d;
char a[1005][1005];
bool aa[1005][1005];
bool bl(int x, int y) {
if(x < 1 || x > n || y < 1 || y > m || a[x][y] == 'x') {
d = (d + 1) % 4;
return 0;
}else return 1;
}
int main() {
int t, x, y, k, ans;
cin >> t;
while(t--) {
ans = 0;
cin >> n >> m >> k;
cin >> x >> y >> d;
rep(i, n) rep(j, m) cin >> a[i][j];
aa[x][y] = 1;
while(k--) {
if(d == 0 && bl(x, y + 1)) aa[x][++y] = 1;
else if(d == 1 && bl(x + 1, y)) aa[++x][y] = 1;
else if(d == 2 && bl(x, y - 1)) aa[x][--y] = 1;
else if(d == 3 && bl(x - 1, y)) aa[--x][y] = 1;
}
rep(i, n) rep(j, m) if(aa[i][j] == 1) ans++, aa[i][j] = 0;
cout << ans << endl;
}
return 0;
}