#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
int nn, m, time, flag, book[2][11][11];
char map[2][11][11];
int dir[4][2]={0, 1, 1, 0, 0, -1, -1, 0};
struct node{
int x, y, z, tim;
}p;
void bfs()
{
node a, n; flag=0;
queue<node>q;
memset(book,0,sizeof(book));
book[0][0][0]=1;
a.x=0; a.y=0; a.z=0; a.tim=0;
q.push(a);
while(!q.empty())
{
a=q.front(); q.pop();
if(map[a.z][a.x][a.y]=='P' && a.tim<=time)
{
flag=1;
return ;
}
for(int i=0;i<4;i++)
{
n.x=a.x+dir[i][0];
n.y=a.y+dir[i][1];
n.z=a.z;
n.tim=a.tim+1;
if(n.x>=0 && n.x<nn && n.y>=0 && n.y<m && map[n.z][n.x][n.y]!='*')
{
if(map[n.z][n.x][n.y]=='#' && map[!n.z][n.x][n.y]=='*')
continue;
if(map[n.z][n.x][n.y]=='#' && map[!n.z][n.x][n.y]=='#')
continue;
if(map[n.z][n.x][n.y]=='#' && !book[n.z][n.x][n.y] && !book[!n.z][n.x][n.y])
{
book[n.z][n.x][n.y]=1;
n.z=!n.z;
book[n.z][n.x][n.y]=1;
q.push(n);
}
if(map[n.z][n.x][n.y]!='#' && !book[n.z][n.x][n.y])
{
book[n.z][n.x][n.y]=1;
q.push(n);
}
}
}
}
}
int main()
{
int i, j, temp, t;
scanf("%d", &t);
while(t--)
{
scanf("%d%d%d", &nn, &m, &time);
for(i=0;i<2;i++)
for(j=0;j<nn;j++)
scanf("%s", &map[i][j]);
bfs();
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}