rt.
#include<iostream>
using namespace std;
struct node{
char t;
int checkk;
}a[1145][1145];
int T,n,m,k,x,y,d,ans = 1;
int xw[11] = {0,1,0,-1},yw[11] = {1,0,-1,0};
int main(){
cin >> T;
while(T--){
cin >> n >> m >> k >> x >> y >> d;
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
cin >> a[i][j].t;
a[i][j].checkk = 0;
}
}
ans = 1;a[x][y].checkk = 1;
if(a[x-1][y].t == 'x' && a[x][y-1].t == 'x' && a[x][y+1].t == 'x' && a[x+1][y].t == 'x') cout << 1 << endl;
else{
while(k--){
if(a[x+xw[d]][y+yw[d]].t == '.'){
x = x+xw[d],y = y+yw[d];
if(a[x][y].t == '.' && a[x][y].checkk == 0){
++ans;
a[x][y].checkk = 1;
}
}else d = (d+1) % 4;
}
}
cout << ans << endl;
}
return 0;
}