#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,t,xx[
4][
2]={{
1,
0},{
0,
1},{-
1,
0},{
0,-
1}},xp,yp,visit[
2][
11][
11];
char map[
2][
11][
11];
void input(
int x)
{
for(
int i=
0;i<n;i++)
for(
int j=
0;j<m;j++)
{
visit[x][i][j]=
1;
cin>>
map[x][i][j];
if(
map[x][i][j]==
'P')xp=i,yp=j;
}
}
int ABS(
int a)
{
return a>
0?a:-a;
}
bool dfs(
int X,
int Y,
int Z,
int step)
{
int i,j,k,l,x,y,z;
if(
map[Z][X][Y]==
'P')
return 1;
if(step==
0)
return 0;
x=ABS(X-xp)+ABS(Y-yp);
if(x>step)
return 0;
for(i=
0;i<
4;i++)
{
x=X+xx[i][
0];
y=Y+xx[i][
1];
z=Z;
if(x>=
0&&y>=
0&&x<n&&y<m&&visit[z][x][y]&&
map[z][x][y]!=
'*')
{
if(
map[z][x][y]==
'#')z=
1-z;
visit[z][x][y]=
0;
if(
map[z][x][y]!=
'#'&&
map[z][x][y]!=
'*'&&dfs(x,y,z,step-
1))
return 1;
visit[z][x][y]=
1;
}
}
return 0;
}
int main (
void)
{
int T,i,j,k,l;
cin>>T;
while(T--&&
cin>>n>>m>>t)
{
input(
0);
input(
1);
if(dfs(
0,
0,
0,t))
cout<<
"YES"<<endl;
else cout<<
"NO"<<endl;
}
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-18640.html