#include<bits/stdc++.h>usingnamespace std;char mp[2][11][11];bool vis[2][11][11];int dir[][2]={{1,0},{-1,0},{0,1},{0,-1}};int n, m, T;structnode{int z, x, y, step;node(){};node(int z,int x,int y,int step):z(z),x(x),y(y),step(step){};}st, en;boolcheck(int z,int x,int y){return z >=0&& z <2&& x >=0&& x < n && y >=0&& y < m
&& mp[z][x][y]!='*';}voidbfs(){memset(vis,false,sizeof(vis));
queue<node> q;
q.push(node(0,0,0,0));
vis[0][0][0]=true;while(!q.empty()){
node cur = q.front(); q.pop();int z = cur.z, x = cur.x, y = cur.y, step = cur.step;if(z == en.z && x == en.x && y == en.y){
cout <<"YES"<< endl;return;}for(int i =0; i <4; i++){int nx = x + dir[i][0], ny = y + dir[i][1], nz = z;if(check(nz, nx, ny)&&!vis[nz][nx][ny]&& step+1<= T){
vis[nz][nx][ny]=true;if(mp[nz][nx][ny]=='#'){if(vis[!nz][nx][ny]|| mp[!nz][nx][ny]=='*'|| mp[!nz][nx][ny]=='#'){continue;}
vis[!nz][nx][ny]=true;
nz =!z;}
q.push(node(nz, nx, ny, step+1));}}}
cout <<"NO"<< endl;return;}intmain(){int t; cin >> t;while(t--){
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]=='S') st =node(c, i, j,0);elseif(mp[c][i][j]=='P') en =node(c, i, j,0);}}}bfs();}}