#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 10+10;
char mp[10][maxn][maxn];
int n, m, t;
int dx[6] = {1, -1, 0, 0, 0, 0};
int dy[6] = {0, 0, -1, 1, 0, 0};
int dz[6] = {0, 0, 0, 0, 1, -1};
struct Node{
int num[3];
int ans = 0;
};
int tx, ty, tz;
bool vis[maxn][maxn][maxn];
bool check(int x, int y, int z){
if(z<0||z>=2||x<0||x>=n||y<0||y>=m) return false;
if(mp[z][x][y] == '*') return false;
if(vis[z][x][y]) return false;
return true;
}
queue<Node> q;
void bfs(){
Node temp;
temp.num[0] = temp.num[1] = temp.num[2] = 0;
temp.ans = 0;
cls(vis, 0);
while(!q.empty()) q.pop();
q.push(temp);
while(!q.empty()){
temp = q.front();
q.pop();
int x = temp.num[0], y = temp.num[1], z = temp.num[2];
if(vis[z][x][y]) continue;
if(temp.num[0] == tx &&temp.num[1] == ty && temp.num[2] == tz){
if(temp.ans<=t) {
cout<<"YES"<<endl;
return ;
}
else continue;
}
vis[z][x][y] = true;
Node temp1;
for(int i=0; i<6; i++){
int nx = dx[i]+x;
int ny = dy[i]+y;
int nz = dz[i]+z;
if(dz[i] && check(nx, ny, nz)&&mp[z][x][y] == '#'&&mp[nz][nx][ny]!='#'){
temp1.ans = temp.ans;
temp1.num[0] = nx, temp1.num[1] = ny, temp1.num[2] = nz;
q.push(temp1);
}
else if(dz[i] == 0&&check(nx, ny, nz)&&(mp[z][x][y] !='#')){
temp1.ans = temp.ans+1;
temp1.num[0] = nx, temp1.num[1] = ny, temp1.num[2] = nz;
q.push(temp1);
}
}
}
cout<<"NO"<<endl;
return ;
}
int main(){
ios::sync_with_stdio(false);
int _;
cin>>_;
while(_--){
cin>>n>>m>>t;
for(int c=0; c<2; c++) for(int i=0; i<n; i++) for(int j=0; j<m; j++) {
cin>>mp[c][i][j];
if(mp[c][i][j] == 'P') tx=i, ty=j, tz=c;
}
bfs();
}
return 0;
}