#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
int dx[4]= {1,0,-1,0};
int dy[4]= {0,-1,0,1};
int sx,sy,sz;
struct point
{
public:
int x,y,z;
point(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
};
int n,m,T;
char pos[11][11][2];
int vis[11][11][2];
int step[11][11][2];
void bfs()
{
step[0][0][0] = 0;
queue<point> q;
q.push(point(0,0,0));
vis[0][0][0] = 1;
while(!q.empty())
{
point p1 = q.front();
q.pop();
int x = p1.x;
int y = p1.y;
int z = p1.z;
int tmp_step = step[x][y][z];
// cout<<tmp_step<<endl;
if(pos[x][y][z]=='P')
break;
for(int i = 0; i < 4; i++)
{
int x1 =x+dx[i];
int y1 =y+dy[i];
if(x1>=0&&x1<n&&y1>=0&&y1<m&&pos[x1][y1][z]!='*'&&!vis[x1][y1][z])
{
if(pos[x1][y1][z]=='.'||pos[x1][y1][z]=='P')
{
step[x1][y1][z] = tmp_step + 1;
q.push(point(x1,y1,z));
vis[x1][y1][z] = 1;
}
else if(pos[x1][y1][z]=='#')
{
vis[x1][y1][z] = 1;
int d = (z+1)%2;
if(pos[x1][y1][d]=='*'||vis[x1][y1][d]||pos[x1][y1][d]=='#')
;
else
{
q.push(point(x1,y1,d));
step[x1][y1][d] = tmp_step+1;
vis[x1][y1][d] = 1;
}
}
}
}
}
}
void init()
{
memset(vis,0,sizeof(vis));
cin>>n>>m;
cin>>T;
for(int k = 0; k < 2; k ++)
{
if(k)
getchar();
for(int i = 0; i < n; i ++)
{
getchar();
for(int j = 0; j < m; j ++)
{
char ch;
cin>>ch;
if(ch=='P')
{
sx = i;
sy = j;
sz = k;
}
pos[i][j][k] = ch;
step[i][j][k] = inf;
}
}
}
// for(int i = 0; i < n; i ++)
// {
// for(int j = 0; j < m; j ++)
// printf("%c",pos[i][j][0]);
// printf("\n");
// }
}
int main()
{
// freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--)
{
init();
bfs();
if(step[sx][sy][sz]<=T)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}