shiyuxuan0429 @ 2024-10-30 13:36:10
#include<bits/stdc++.h>
using namespace std;
int a[1005][1005];
int b[100000000];
int main(){
int t;
cin>>t;
int x,y,d;
int n,m,k;
for(int i=0;i<t;i++){
a[1005][1005]=0;
cin>>n>>m>>k;
cin>>x>>y>>d;
x-=1;
y-=1;
char s;
int sum=1;
for(int j=0;j<n;j++){
for(int b=0;b<m;b++){
cin>>s;
if(s=='.'){
a[j][b]=1;
}
}
}
while(k>0){
if(d==0){
if(y+1<m&&a[x][y+1]>0){
if(a[x][y+1]==1){
sum+=1;
}
a[x][y+1]+=1;
y+=1;
}
else
d=(d+1)%4;
k-=1;
}
else if(d==1){
if(x+1<n&&a[x+1][y]>0){
if(a[x+1][y]==1){
sum+=1;
}
a[x+1][y]+=1;
x+=1;
}
else
d=(d+1)%4;
k-=1;
}
else if(d==2){
if(y-1>=0&&a[x][y-1]>0){
if(a[x][y-1]==1){
sum+=1;
}
a[x][y-1]+=1;
y-=1;
}
else
d=(d+1)%4;
k-=1;
}
else if(d==3){
if(x-1>=0&&a[x-1][y]>0){
if(a[x-1][y]==1){
sum+=1;
}
a[x-1][y]+=1;
x-=1;
}
else
d=(d+1)%4;
k-=1;
}
}
b[i]=sum;
}
for(int j=0;j<t;j++){
cout<<b[j]<<endl;
}
return 0;
}