#include<bits/stdc++.h>
using namespace std;
int n,m,p,i,j,d,k,x,y,l=0;
char a[1001][1001];
void dp(){
l=1;
while(1){
if(d==0){
if(y+1>=1 and y+1<=m and a[x][y+1]!='x'){
//if(a[x][y]!='y')
l++;
a[x][y]='y';
y++;
d=(d+1)%4;
k--;
cout<<"0 ";
}
else d=(d+1)%4,k--;
}
else if(d==1){
if(x+1>=1 and x+1<=n and a[x+1][y]!='x'){
//if(a[x][y]!='y')
l++;
a[x][y]='y';
x++;
d=(d+1)%4;
k--;
cout<<"1 ";
}
else d=(d+1)%4,k--;
}
else if(d==2){
if(y-1>=1 and y-1<=m and a[x][y-1]!='x'){
//if(a[x][y]!='y')
l++;
a[x][y]='y';
y--;
d=(d+1)%4;
k--;
cout<<"2 ";
}
else d=(d+1)%4,k--;
}
else if(d==3){
if(x-1>=1 and x-1<=n and a[x-1][y]!='x'){
//if(a[x][y]!='y')
l++;
a[x][y]='y';
x--;
d=(d+1)%4;
k--;
cout<<"3 ";
}
else d=(d+1)%4,k--;
}
if(k<=0) return ;
// cout<<"x:"<<x<<" y:"<<y<<" k:"<<k<<" d:"<<d<<"\n";
}
}
int main(){
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int T;
cin>>T;
for(i=1;i<=T;i++){
cin>>n>>m>>k;
cin>>x>>y>>d;
for(j=1;j<=n;j++){
for(p=1;p<=m;p++){
cin>>a[j][p];
}
}
dp();
/* for(j=1;j<=n;j++){
for(p=1;p<=m;p++){
cout<<a[j][p]<<" ";
}
cout<<"\n";
}*/
cout<<l<<"\n";
}
return 0;
}