/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int t;
int n, m, tim;
int sx, sy, sz;
char s[3][15][15];
int vis[3][15][15];
int dist[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};

struct node
{
	int x, y, z, step;
	bool operator <(const node &a)const{
		return step > a.step;
	}
};

void bfs(){
	memset(vis, 0, sizeof(vis));
	priority_queue<node> q;
	vis[sz][sx][sy] = 1;
	q.push(node{sx, sy, sz, 0});
	while(q.size()){
		node t = q.top();
		q.pop();
		for (int i = 0; i < 4; i++){
			int x = t.x + dist[i][0], y = t.y + dist[i][1];
			if(x < 1 || x > n || y < 1 || y > m || s[t.z][x][y] == '*') continue;
			if(!vis[t.z][x][y] || vis[t.z][x][y] > t.step + 1){
				vis[t.z][x][y] = t.step + 1;
				if(s[t.z][x][y] == '#'){
					int z = (t.z == 1 ? 2 : 1);
					if(s[z][x][y] == 'P' && t.step + 1 <= tim){
						printf("YES\n");
						return ;
					}
					if(s[z][x][y] == '.'){
						vis[z][x][y] = t.step + 1;
						q.push(node{x, y, z, t.step + 1});
					}
				}else if(s[t.z][x][y] == '.'){
					q.push(node{x, y, t.z, t.step + 1});
				}else if(s[t.z][x][y] == 'P'){
					if(t.step + 1 <= tim){
						printf("YES\n");
						return ;
					}
				}
			}
		}
	}
	printf("NO\n");
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	scanf("%d", &t);
	while(t--){
		scanf("%d %d %d", &n, &m, &tim);
		for (int i = 1; i <= n; i++){
			scanf("%s", s[1][i] + 1);
			for (int j = 1; j <= m; j++){
				if(s[1][i][j] == 'S'){
					sx = i, sy = j, sz = 1;
				}
			}
		}
		for (int i = 1; i <= n; i++){
			scanf("%s", s[2][i] + 1);
			for (int j = 1; j <= m; j++){
				if(s[2][i][j] == 'S'){
					sx = i, sy = j, sz = 2;
				}
			}
		}
		bfs();
	}

	return 0;
}
/**/