#include <iostream>
#include <cmath>
using namespace std;
char** maze;
int** usedEnergyMaze;
int M, N;
void GetUsedEnergy(int row, int col, int energy)
{
if(row < 0 || col < 0 || row >= M || col >= N)
{
return;
}
if(maze[row][col] == '*')
{
energy++;
}
if(energy < usedEnergyMaze[row][col])
{
usedEnergyMaze[row][col] = energy;
}
else
{
return;
}
GetUsedEnergy(row - 1, col, energy);
GetUsedEnergy(row + 1, col, energy);
GetUsedEnergy(row, col - 1, energy);
GetUsedEnergy(row, col + 1, energy);
}
bool canRescue(int energy)
{
int row, col;
for(int i = 0; i < M; i++)
{
for(int j = 0; j < N; j++)
{
if(maze[i][j] == 'S')
{
row = i;
col = j;
}
}
}
GetUsedEnergy(row, col, 0);
for(int i = 0; i < M; i++)
{
for(int j = 0; j < N; j++)
{
if(maze[i][j] == 'T')
{
if(usedEnergyMaze[i][j] <= energy)
{
return true;
}
}
}
}
return false;
}
int main()
{
int T;
cin >> T;
for(int i = 0; i < T; i++)
{
int k;
cin >> k;
cin >> M >> N;
maze = new char*[M];
for(int j = 0; j < M; j++)
{
maze[j] = new char[N];
}
for(int j = 0; j < M; j++)
{
for(int k = 0; k < N; k++)
{
cin >> maze[j][k];
}
}
usedEnergyMaze = new int*[M];
for(int j = 0; j < M; j++)
{
usedEnergyMaze[j] = new int[N];
}
int intMax = pow(2, 31) - 1;
for(int j = 0; j < M; j++)
{
for(int k = 0; k < N; k++)
{
usedEnergyMaze[j][k] = intMax;
}
}
if(canRescue(k))
{
cout << 'y' << endl;
}
else
{
cout << 'n' << endl;
}
for(int j = 0; j < M; j++)
{
delete[] usedEnergyMaze[j];
}
delete[] usedEnergyMaze;
for(int j = 0; j < M; j++)
{
delete[] maze[j];
}
delete[] maze;
}
return 0;
}