#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499634985089


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499634636131


#include <bits/stdc++.h>

#define N 1000007
#define it(i, n) for(i = 0; i < n; ++i)
#define pb push_back
#define eps 1e-9
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;

char mat[1007][1007];
bool seen[1007][1007][3][4];
int p, q, n, m;
bool ok = false;

void go(int i, int j, int turns, int prev) {
	int alt;
	if(i >= n or i < 0 or j >= m or j < 0 or mat[i][j] == '*' || turns > 2) return;

	if(seen[i][j][turns][prev] == true) return;
	seen[i][j][turns][prev] = true;

	if(i == p and j == q) {
		ok = true;
		return;
	}

	if(prev == 0) go(i+1, j, turns, 0);
	else go(i+1, j, (prev>=0?turns+1:turns), 0);
	if(prev == 1) go(i, j+1, turns, 1);
	else go(i, j+1, (prev>=0?turns+1:turns), 1);
	if(prev == 2) go(i-1, j, turns, 2);
	else go(i-1, j, (prev>=0?turns+1:turns), 2);
	if(prev == 3) go(i, j-1, turns, 3);
	else go(i, j-1, (prev>=0?turns+1:turns), 3);
}

int main(int argc, char * argv[]) {
	int i, j, k, r, t;
	int i0, j0;
	char c;
	scanf("%d %d", &n, &m);

	for(i = 0; i < n; ++i) {
		for(j = 0; j < m; ++j) {
			cin >> c;
			if(c == 'S') {
				i0 = i;
				j0 = j;
			}
			else if(c == 'T') {
				p = i;
				q = j;
			}
			mat[i][j] = c;
		}
	}

	go(i0, j0, 0, -1);

	cout << (ok? "YES" : "NO") << endl;

	return 0;
}
// 1498073494582


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499705877573


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499783074824


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499627732457


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499715583368


#include <bits/stdc++.h>
using namespace std;

bool ter[1007][1007];
int vis[1007][1007][3][4];

int ok = false;
int r, s;
int n, m;

int moves[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

bool valid(int i, int j) {
	return i < n && i >= 0 && j < m && j >= 0 && ter[i][j] == false;
}

void solve(int i, int j, int c, int dir) {
	if(c > 2) return;
	if(vis[i][j][c][dir]) return;
	vis[i][j][c][dir] = 1;

	if(i == r && j == s) ok = true;

	for(int k = 0; k < 4; ++k) {
		int p, q;
		p = i + moves[k][0];
		q = j + moves[k][1];
		if(valid(p, q)) {
			solve(p, q, c + (k != dir), k);
		}
	}
}

int main() {

	int p, q;

	cin >> n >> m;

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			char c;
			cin >> c;
			if(c == 'S') {
				p = i;
				q = j;
			}
			if(c == 'T') {
				r = i;
				s = j;
			}
			ter[i][j] = c == '*';
		}
	}

	for(int i = 0; i < 4; ++i) {
		int x, y;
		x = p + moves[i][0];
		y = q + moves[i][1];
		if(valid(x, y)) solve(x, y, 0, i);
	}

	cout << (ok? "YES\n" : "NO\n");

}
// 1499375477902


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499780244506


#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i = int(a) ; i < int(b) ; i++)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<bool> vb;

vector<pair<int, int> > positions;

struct node
{
    int pos;
    int indir;
    int turns;
};

class Graph
{
    private:

        int col;
        int row;
        int N;
        vector<vii> adjList;
        bool visited[1004004][5][3];

    public:
        Graph(vector<vector<int> > field)
        {
            row = field.size();
            col = field[0].size();
            N = row*col;
            vector<vii> adjList2(N);
            REP(q,0,row)
            {
                REP(w,0,col)
                {
                    int posa=q;
                    int posb=w;
                    int nodes = q*row+w;
                    int noded;
                    for(int e = 0 ; e < 4 ; e++)
                    {
                        posa = q+positions[e].first;
                        posb = w+positions[e].second;
                        if(checkEdge(posa,posb))
                        {
                            if(field[posa][posb]==0)
                            {
                                noded = posa*row+posb;
                                adjList2[nodes].push_back(make_pair(noded,e));
                            }
                        }
                    }
                }
            }
            adjList = adjList2;
        }

        bool checkEdge(int posx, int posy)
        {
            return ((posx>=0 && posy >=0 && posx < row && posy < col));
        }

        bool letsTourAroundYay(int S, int T)
        {
        	queue<node> pq;
        	node s;
        	s.pos=S;
        	s.indir=4;
        	s.turns=0;
        	pq.push(s);
            visited[S][4][0] = true;
    	    while(!pq.empty())
    	    {
        		node uu = pq.front();
        		int u = uu.pos;
        		pq.pop();
        		if(u == T) return true;
                int dir = uu.indir;
                int tuturu = uu.turns;
        		REP(j,0,adjList[u].size())
        		{
        			int v = adjList[u][j].first;
        			int vdir = adjList[u][j].second;

        			node vv;
        			vv.pos=v;
        			vv.indir=vdir;
        			if(dir != 4 && vdir!=dir) vv.turns = tuturu+1;
    			    else vv.turns = tuturu;

        			if (vv.turns <=2 && !visited[v][vdir][vv.turns])
        			{
        				pq.push(vv);
        				visited[v][vdir][vv.turns]=true;
        				//cout << v << " " << vdir << " " << tuturu << endl;
        			}
        		}
        	}
            return false;
        }

};

void makeField(vector<vector<int> > & a, int R, int C)
{
    REP(i,0,R)
    {
        vector<int> tempo;
        REP(i,0,C)
        {
            tempo.push_back(0);
        }
        a.push_back(tempo);
    }
}

void process(vector<vector<int> > & field, int S, int T)
{

    Graph* G = new Graph(field);
    if(G->letsTourAroundYay(S,T)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

ii converterStoI(string a, vector<vector<int> > & mat, int currentRow)
{
    int aux = 0;
    int s=-1;
    int t=-1;
    for(string::iterator it = a.begin(); it != a.end(); ++it)
    {
        if((*it) == '*')
        {
            mat[currentRow][aux] = 1;
        }
        else if((*it) == '.')
        {
            mat[currentRow][aux] = 0;
        }
        else if((*it) == 'S')
        {
            mat[currentRow][aux] = 0;
            s = aux;
        }
        else
        {
            mat[currentRow][aux] = 0;
            t = aux;
        }
        aux++;
    }
    return make_pair(s,t);
}

int main()
{
	int R, C, S, T;
	cin >> R;
	cin >> C;
	S = T = 0;
    vector<vector<int> > field;
    makeField(field,R,C);

    positions.push_back(make_pair(-1,0));
    positions.push_back(make_pair(1,0));
    positions.push_back(make_pair(0,1));
    positions.push_back(make_pair(0,-1));
    int aux = 0;
    REP(i,0,R)
    {
        string dummy;
        REP(j,0,C)
        {
            char dum;
            cin >> dum;
            dummy = dummy + dum;
        }
        //cout << dummy << endl;
        ii st = converterStoI(dummy,field,aux);
        if(st.first!=-1) S = R*aux+st.first;
        if(st.second!=-1) T = R*aux+st.second;
        aux++;
    }
    process(field,S,T);

	return 0;
}

// 1498639748238


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499627082374


#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i = int(a) ; i < int(b) ; i++)

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<bool> vb;

vector<pair<int, int> > positions;

struct node
{
    int pos;
    int indir;
    int turns;
};

class Graph
{
    private:

        int col;
        int row;
        int N;
        vector<vii> adjList;
        bool visited[1004004][5][3];

    public:
        Graph(vector<vector<int> > field)
        {
            row = field.size();
            col = field[0].size();
            N = row*col;
            vector<vii> adjList2(N);
            REP(q,0,row)
            {
                REP(w,0,col)
                {
                    int posa=q;
                    int posb=w;
                    int nodes = q*col+w;
                    int noded;
                    for(int e = 0 ; e < 4 ; e++)
                    {
                        posa = q+positions[e].first;
                        posb = w+positions[e].second;
                        if(checkEdge(posa,posb))
                        {
                            if(field[posa][posb]==0)
                            {
                                noded = posa*col+posb;
                                adjList2[nodes].push_back(make_pair(noded,e));
                            }
                        }
                    }
                }
            }
            adjList = adjList2;
        }

        bool checkEdge(int posx, int posy)
        {
            return ((posx>=0 && posy >=0 && posx < row && posy < col));
        }

        bool letsTourAroundYay(int S, int T)
        {
        	queue<node> pq;
        	node s;
        	s.pos=S;
        	s.indir=4;
        	s.turns=0;
        	pq.push(s);
            visited[S][4][0] = true;
    	    while(!pq.empty())
    	    {
        		node uu = pq.front();
        		int u = uu.pos;
        		pq.pop();
        		if(u == T) return true;
                int dir = uu.indir;
                int tuturu = uu.turns;
        		REP(j,0,adjList[u].size())
        		{
        			int v = adjList[u][j].first;
        			int vdir = adjList[u][j].second;

        			node vv;
        			vv.pos=v;
        			vv.indir=vdir;
        			if(dir != 4 && vdir!=dir) vv.turns = tuturu+1;
    			    else vv.turns = tuturu;

        			if (vv.turns <=2 && !visited[v][vdir][vv.turns])
        			{
        				pq.push(vv);
        				visited[v][vdir][vv.turns]=true;
        				//cout << v << " " << vdir << " " << tuturu << endl;
        			}
        		}
        	}
            return false;
        }

};

void makeField(vector<vector<int> > & a, int R, int C)
{
    REP(i,0,R)
    {
        vector<int> tempo;
        REP(i,0,C)
        {
            tempo.push_back(0);
        }
        a.push_back(tempo);
    }
}

void process(vector<vector<int> > & field, int S, int T)
{

    Graph* G = new Graph(field);
    if(G->letsTourAroundYay(S,T)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

ii converterStoI(string a, vector<vector<int> > & mat, int currentRow)
{
    int aux = 0;
    int s=-1;
    int t=-1;
    for(string::iterator it = a.begin(); it != a.end(); ++it)
    {
        if((*it) == '*')
        {
            mat[currentRow][aux] = 1;
        }
        else if((*it) == '.')
        {
            mat[currentRow][aux] = 0;
        }
        else if((*it) == 'S')
        {
            mat[currentRow][aux] = 0;
            s = aux;
        }
        else
        {
            mat[currentRow][aux] = 0;
            t = aux;
        }
        aux++;
    }
    return make_pair(s,t);
}

int main()
{
	int R, C, S, T;
	cin >> R;
	cin >> C;
	S = T = 0;
    vector<vector<int> > field;
    makeField(field,R,C);

    positions.push_back(make_pair(-1,0));
    positions.push_back(make_pair(1,0));
    positions.push_back(make_pair(0,1));
    positions.push_back(make_pair(0,-1));
    int aux = 0;
    REP(i,0,R)
    {
        string dummy;
        REP(j,0,C)
        {
            char dum;
            cin >> dum;
            dummy = dummy + dum;
        }
        //cout << dummy << endl;
        ii st = converterStoI(dummy,field,aux);
        if(st.first!=-1) S = C*aux+st.first;
        if(st.second!=-1) T = C*aux+st.second;
        aux++;
    }
    //cout << S << " " << T;
    process(field,S,T);

	return 0;
}
// 1498681887620


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499627861992


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499915940682


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499715273487


#include <bits/stdc++.h>

using namespace std;

char c[1002][1002];

int di[4] = {-1,0,1,0} ,dj[4] = {0,1,0,-1};

int n,m;

int dp[1002][1002][4];

int rec(int i,int j, int s, int qtdCurvas){ // s = 0 --> I    s = 1 -- J

	if(i<0 || i>=n || j<0 || j>=m || qtdCurvas > 2 || c[i][j] == '*'){ // invalido
		return 0;
	}

	if(c[i][j] == 'T') return 1;

	if(dp[i][j][s]  <= qtdCurvas){
		return 0;
	}

	dp[i][j][s] = qtdCurvas;

	for(int k=0;k<4;k++){
		if(s!=k){ // fez curva
			if(rec(i+di[k],j+dj[k],k,qtdCurvas+1)) {
				return 1;
			}
		}else if(rec(i+di[k],j+dj[k],k,qtdCurvas)){
			 return 1;
		}
	}

	return 0;
}

int main(){

	memset(dp, 3,sizeof dp); // num giga

	scanf("%d %d",&n,&m);
	int ini = 0,jni = 0;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf(" %c",&c[i][j]);
			if(c[i][j] == 'S'){
				ini = i;
				jni = j;

			}
		}
	}

	for(int i=0;i<4;i++){
		if(rec(ini,jni,i,0)) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");

	return 0;
}

// 1499716038140


#include <bits/stdc++.h>
using namespace std;
char ma[1010][1010];
int vis[1010][1010];
int dp[1010][1010];
int di[4]={-1,0,1,0};
int dj[4]={0,1,0,-1};

int ei;
int ej;

int n,m;

int dfs(int i,int j,int cv,int dir){
	if(cv>2)
		return 0;
	if(ma[i][j]=='T')
		return 1;
	if(ma[i][j]=='*')
		return 0;
	if(i>=n||j>=m||i<0||j<0)
		return 0;

	if(cv>dp[i][j])
		return 0;

	dp[i][j]=cv;

	for(int d=0;d<4;d++){
		if(d!=dir){
			if(dfs(i+di[d],j+dj[d],cv+1,d))
				return 1;
		}else
			if(dfs(i+di[d],j+dj[d],cv,d))
				return 1;
	}
	return 0;
}

int main(){
	memset(dp,4,sizeof(dp));
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf(" %s",ma[i]);
		for(int j=0;j<m;j++){
			if(ma[i][j]=='S'){
				ei=i;
				ej=j;
			}
		}
	}
	if(dfs(ei,ej,0,0)||dfs(ei,ej,0,1)||dfs(ei,ej,0,2)||dfs(ei,ej,0,3))
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

// 1499456196916


#include <bits/stdc++.h>
using namespace std;
char ma[1010][1010];
int vis[1010][1010];
int dp[1010][1010][4];
int di[4]={-1,0,1,0};
int dj[4]={0,1,0,-1};

int ei;
int ej;

int n,m;

int dfs(int i,int j,int cv,int dir){
	if(cv>2)
		return 0;
	if(ma[i][j]=='T')
		return 1;
	if(ma[i][j]=='*')
		return 0;
	if(i>=n||j>=m||i<0||j<0)
		return 0;

	if(cv>=dp[i][j][dir])
		return 0;
	dp[i][j][dir]=cv;

	for(int d=0;d<4;d++){
		if(d!=dir){
			if(dfs(i+di[d],j+dj[d],cv+1,d))
				return 1;
		}else
			if(dfs(i+di[d],j+dj[d],cv,d))
				return 1;
	}
	return 0;
}

int main(){
	memset(dp,4,sizeof(dp));
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf(" %s",ma[i]);
		for(int j=0;j<m;j++){
			if(ma[i][j]=='S'){
				ei=i;
				ej=j;
			}
		}
	}
	if(dfs(ei,ej,0,0)||dfs(ei,ej,0,1)||dfs(ei,ej,0,2)||dfs(ei,ej,0,3))
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}
// 1499731313686


#include <bits/stdc++.h>
using namespace std;
char ma[1010][1010];
int vis[1010][1010];
int dp[1010][1010][4];
int di[4]={-1,0,1,0};
int dj[4]={0,1,0,-1};

int ei;
int ej;

int n,m;

int dfs(int i,int j,int cv,int dir){
	if(cv>2)
		return 0;
	if(ma[i][j]=='T')
		return 1;
	if(ma[i][j]=='*')
		return 0;
	if(i>=n||j>=m||i<0||j<0)
		return 0;

	if(cv>=dp[i][j][dir])
		return 0;
	dp[i][j][dir]=cv;

	for(int d=0;d<4;d++){
		if(d!=dir){
			if(dfs(i+di[d],j+dj[d],cv+1,d))
				return 1;
		}else
			if(dfs(i+di[d],j+dj[d],cv,d))
				return 1;
	}
	return 0;
}

int main(){
	memset(dp,4,sizeof(dp));
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf(" %s",ma[i]);
		for(int j=0;j<m;j++){
			if(ma[i][j]=='S'){
				ei=i;
				ej=j;
			}
		}
	}
	if(dfs(ei,ej,0,0)||dfs(ei,ej,0,1)||dfs(ei,ej,0,2)||dfs(ei,ej,0,3))
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}
// 1499731444149


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const int MX=1005;
const double PI = acos(-1.0), EPS = 1e-9;
int N, M;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
bool ok(int x, int y)
{
    return x >= 0 && y >= 0 && x < N && y < M;
}
int dis[MX][MX];
string g[MX];
char s[MX];
int save[MX][MX];
deque<pair<int, int> > dq;
void bfs(int i, int j, int dir)
{

    dq.clear();
    memset(save, 0, sizeof save);
    dq.pb(mp(i, j));
    dis[i][j]=0;
    for(int d=0;d<4;d++)
    {
        if(dir != d) continue;
        int ii=i+dx[d];
        int jj=j+dy[d];
        if(ok(ii, jj) && g[ii][jj] != '*')
        {
            dis[ii][jj]=0;
            if(d == 0)
                save[ii][jj]=1;
            else if(d == 1)
                save[ii][jj]=2;
            else if(d == 2) save[ii][jj]=3;
            else save[ii][jj]=4;
            dq.pb(mp(ii, jj));
        }
    }
    while(dq.size())
    {
        int x=dq.front().F;
        int y=dq.front().S;
        dq.pop_front();
        for(int d=0;d<4;d++)
        {
            int xx=x+dx[d];
            int yy=y+dy[d];
            if(!ok(xx, yy) || g[xx][yy] == '*') continue;
            if(dis[xx][yy] >= dis[x][y])
            {
                dis[xx][yy]=dis[x][y];
                if(d == 0 && save[x][y] != 1) dis[xx][yy]++;
                if(d == 1 && save[x][y] != 2) dis[xx][yy]++;
                if(d == 2 && save[x][y] != 3) dis[xx][yy]++;
                if(d == 3 && save[x][y] != 4) dis[xx][yy]++;
                if(d == 0)
                    save[xx][yy]=1;
                else if(d == 1)
                    save[xx][yy]=2;
                else if(d == 2) save[xx][yy]=3;
                else save[xx][yy]=4;
                if(dis[xx][yy] < 3)
                    dq.pb(mp(xx, yy));
            }
        }
    }
}
int main()
{

    scanf("%d %d", &N, &M);
    int ii, jj, ei, ej;
    for(int i=0;i<N;i++)
    {
        scanf("%s", &s);
        g[i]=s;
    }
     for(int i=0;i<=N;i++)
    {
        for(int j=0;j<=M;j++)
        {
            dis[i][j]=1e9;
        }
    }
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
           // cout<<dis[i][j]<<" ";
               if(g[i][j] == 'S')
            {
                ii=i;
                jj=j;
            }
            if(g[i][j] == 'T')
            {
                ei=i;
                ej=j;
            }
        }
      ///  cout<<"\n";
    }
    bool ok=0;
    for(int i=0;i<4;i++)
    {
        bfs(ii, jj, i);
        if(dis[ei][ej] < 3) {cout<<"YES\n"; ok=1; break;}
    }
    if(!ok) cout<<"NO\n";
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const int MX=1234567;
const double PI = acos(-1.0), EPS = 1e-9;
int N, M;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
bool ok(int x, int y)
{
    return x >= 0 && y >= 0 && x < N && y < M;
}
int dis[1112][1112];
string g[1111];
char s[1111];
int save[1112][1112];
void bfs(int i, int j, int dir)
{
    for(int i=0;i<=N;i++)
    {
        for(int j=0;j<=M;j++)
        {
            dis[i][j]=1e9;
        }
    }
    deque<pair<int, int> > dq;
    memset(save, 0, sizeof save);
    dq.pb(mp(i, j));
    dis[i][j]=0;
    for(int d=0;d<4;d++)
    {
        if(dir != d) continue;
        int ii=i+dx[d];
        int jj=j+dy[d];
        if(ok(ii, jj) && g[ii][jj] != '*')
        {
            dis[ii][jj]=0;
            if(d == 0)
                save[ii][jj]=1;
            else if(d == 1)
                save[ii][jj]=2;
            else if(d == 2) save[ii][jj]=3;
            else save[ii][jj]=4;
            dq.pb(mp(ii, jj));
        }
    }
    while(dq.size())
    {
        int x=dq.front().F;
        int y=dq.front().S;
        dq.pop_front();
        for(int d=0;d<4;d++)
        {
            int xx=x+dx[d];
            int yy=y+dy[d];
            if(!ok(xx, yy) || g[xx][yy] == '*') continue;
            if(dis[xx][yy] > dis[x][y])
            {
                dis[xx][yy]=dis[x][y];
                if(d == 0 && save[x][y] != 1) dis[xx][yy]++;
                if(d == 1 && save[x][y] != 2) dis[xx][yy]++;
                if(d == 2 && save[x][y] != 3) dis[xx][yy]++;
                if(d == 3 && save[x][y] != 4) dis[xx][yy]++;
                if(d == 0)
                    save[xx][yy]=1;
                else if(d == 1)
                    save[xx][yy]=2;
                else if(d == 2) save[xx][yy]=3;
                else save[xx][yy]=4;
                if(dis[xx][yy] < 3)
                    dq.pb(mp(xx, yy));
            }
        }
    }
}
int main()
{

    scanf("%d %d", &N, &M);
    int ii, jj, ei, ej;
    for(int i=0;i<N;i++)
    {
        scanf("%s", &s);
        g[i]=s;
    }

    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
           // cout<<dis[i][j]<<" ";
               if(g[i][j] == 'S')
            {
                ii=i;
                jj=j;
            }
            if(g[i][j] == 'T')
            {
                ei=i;
                ej=j;
            }
        }
      ///  cout<<"\n";
    }
  ///  bfs(ii, jj);
   /* for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
            cout<<dis[i][j]<<" ";
        }
        cout<<endl;
    }*/
    bool ok=0;
    for(int i=0;i<4;i++)
    {
        bfs(ii, jj, i);
        if(dis[ei][ej] < 3) {cout<<"YES\n"; ok=1; break;}
    }

    if(!ok) cout<<"NO\n";
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const int MX=1234567;
const double PI = acos(-1.0), EPS = 1e-9;
int N, M;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
bool ok(int x, int y)
{
    return x >= 0 && y >= 0 && x < N && y < M;
}
int dis[1112][1112];
string g[1111];
char s[1111];
int save[1112][1112];
void bfs(int i, int j)
{
    deque<pair<int, int> > dq;
    memset(save, 0, sizeof save);
    dq.pb(mp(i, j));
    dis[i][j]=0;
    for(int d=0;d<4;d++)
    {
        int ii=i+dx[d];
        int jj=j+dy[d];
        if(ok(ii, jj) && g[ii][jj] != '*')
        {
            dis[ii][jj]=0;
            if(d == 0)
                save[ii][jj]=1;
            else if(d == 1)
                save[ii][jj]=2;
            else if(d == 2) save[ii][jj]=3;
            else save[ii][jj]=4;
            dq.pb(mp(ii, jj));
        }
    }
    while(dq.size())
    {
        int x=dq.front().F;
        int y=dq.front().S;
        dq.pop_front();
        for(int d=0;d<4;d++)
        {
            int xx=x+dx[d];
            int yy=y+dy[d];
            if(!ok(xx, yy) || g[xx][yy] == '*') continue;
            if(dis[xx][yy] > dis[x][y])
            {
                dis[xx][yy]=dis[x][y];
                if(d == 0 && save[x][y] != 1) dis[xx][yy]++;
                if(d == 1 && save[x][y] != 2) dis[xx][yy]++;
                if(d == 2 && save[x][y] != 3) dis[xx][yy]++;
                if(d == 3 && save[x][y] != 4) dis[xx][yy]++;
                if(d == 0)
                    save[xx][yy]=1;
                else if(d == 1)
                    save[xx][yy]=2;
                else if(d == 2) save[xx][yy]=3;
                else save[xx][yy]=4;
                if(dis[xx][yy] < 3)
                    dq.pb(mp(xx, yy));
            }
        }
    }
}
int main()
{

    scanf("%d %d", &N, &M);
    int ii, jj, ei, ej;
    for(int i=0;i<N;i++)
    {
        scanf("%s", &s);
        g[i]=s;
    }
    for(int i=0;i<=N;i++)
    {
        for(int j=0;j<=M;j++)
        {
            dis[i][j]=1e9;
        }
    }
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
           // cout<<dis[i][j]<<" ";
               if(g[i][j] == 'S')
            {
                ii=i;
                jj=j;
            }
            if(g[i][j] == 'T')
            {
                ei=i;
                ej=j;
            }
        }
      ///  cout<<"\n";
    }
    bfs(ii, jj);
   /* for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
            cout<<dis[i][j]<<" ";
        }
        cout<<endl;
    }*/
    if(dis[ei][ej] < 3) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const int MX=1234567;
const double PI = acos(-1.0), EPS = 1e-9;
int N, M;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
bool ok(int x, int y)
{
    return x >= 0 && y >= 0 && x < N && y < M;
}
int dis[1112][1112];
string g[1111];
char s[1111];
int save[1112][1112];
void bfs(int i, int j)
{
    deque<pair<int, int> > dq;
    memset(save, 0, sizeof save);
    dq.pb(mp(i, j));
    dis[i][j]=0;
    for(int d=0;d<4;d++)
    {
        int ii=i+dx[d];
        int jj=j+dy[d];
        if(ok(ii, jj) && g[ii][jj] != '*')
        {
            dis[ii][jj]=0;
            if(d == 0)
                save[ii][jj]=1;
            else if(d == 1)
                save[ii][jj]=2;
            else if(d == 2) save[ii][jj]=3;
            else save[ii][jj]=4;
            dq.pb(mp(ii, jj));
        }
    }
    while(dq.size())
    {
        int x=dq.front().F;
        int y=dq.front().S;
        dq.pop_front();
        for(int d=0;d<4;d++)
        {
            int xx=x+dx[d];
            int yy=y+dy[d];
            if(!ok(xx, yy) || g[xx][yy] == '*') continue;
            if(dis[xx][yy] > dis[x][y])
            {
                dis[xx][yy]=dis[x][y];
                if(d == 0 && save[x][y] != 1) dis[xx][yy]++;
                if(d == 1 && save[x][y] != 2) dis[xx][yy]++;
                if(d == 2 && save[x][y] != 3) dis[xx][yy]++;
                if(d == 3 && save[x][y] != 4) dis[xx][yy]++;
                if(d == 0)
                    save[xx][yy]=1;
                else if(d == 1)
                    save[xx][yy]=2;
                else if(d == 2) save[xx][yy]=3;
                else save[xx][yy]=4;
                dq.pb(mp(xx, yy));
            }
        }
    }
}
int main()
{
    for(int i=0;i<1101;i++)
    {
        for(int j=0;j<1101;j++)
        {
            dis[i][j]=1e9;
        }
    }
    cin>>N>>M;
    int ii, jj, ei, ej;
    for(int i=0;i<N;i++)
    {
        scanf("%s", &s);
        g[i]=s;
    }

    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
           // cout<<dis[i][j]<<" ";
               if(g[i][j] == 'S')
            {
                ii=i;
                jj=j;
            }
            if(g[i][j] == 'T')
            {
                ei=i;
                ej=j;
            }
        }
      ///  cout<<"\n";
    }
    bfs(ii, jj);
    if(dis[ei][ej] < 3) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const int MX=1005;
const double PI = acos(-1.0), EPS = 1e-9;
int N, M;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
bool ok(int x, int y)
{
    return x >= 0 && y >= 0 && x < N && y < M;
}
int dis[MX][MX];
string g[MX];
char s[MX];
int save[MX][MX];
deque<pair<int, int> > dq;
void bfs(int i, int j, int dir)
{

    dq.clear();
    memset(save, 0, sizeof save);
    dq.pb(mp(i, j));
    dis[i][j]=0;
    for(int d=0;d<4;d++)
    {
        if(dir != d) continue;
        int ii=i+dx[d];
        int jj=j+dy[d];
        if(ok(ii, jj) && g[ii][jj] != '*')
        {
            dis[ii][jj]=0;
            if(d == 0)
                save[ii][jj]=1;
            else if(d == 1)
                save[ii][jj]=2;
            else if(d == 2) save[ii][jj]=3;
            else save[ii][jj]=4;
            dq.pb(mp(ii, jj));
        }
    }
    while(dq.size())
    {
        int x=dq.front().F;
        int y=dq.front().S;
        dq.pop_front();
        for(int d=0;d<4;d++)
        {
            int xx=x+dx[d];
            int yy=y+dy[d];
            if(!ok(xx, yy) || g[xx][yy] == '*') continue;
            if(dis[xx][yy] > dis[x][y])
            {
                dis[xx][yy]=dis[x][y];
                if(d == 0 && save[x][y] != 1) dis[xx][yy]++;
                if(d == 1 && save[x][y] != 2) dis[xx][yy]++;
                if(d == 2 && save[x][y] != 3) dis[xx][yy]++;
                if(d == 3 && save[x][y] != 4) dis[xx][yy]++;
                if(d == 0)
                    save[xx][yy]=1;
                else if(d == 1)
                    save[xx][yy]=2;
                else if(d == 2) save[xx][yy]=3;
                else save[xx][yy]=4;
                if(dis[xx][yy] < 3)
                    dq.pb(mp(xx, yy));
            }
        }
    }
}
int main()
{

    scanf("%d %d", &N, &M);
    int ii, jj, ei, ej;
    for(int i=0;i<N;i++)
    {
        scanf("%s", &s);
        g[i]=s;
    }
     for(int i=0;i<=N;i++)
    {
        for(int j=0;j<=M;j++)
        {
            dis[i][j]=1e9;
        }
    }
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
           // cout<<dis[i][j]<<" ";
               if(g[i][j] == 'S')
            {
                ii=i;
                jj=j;
            }
            if(g[i][j] == 'T')
            {
                ei=i;
                ej=j;
            }
        }
      ///  cout<<"\n";
    }
    bool ok=0;
    for(int i=0;i<4;i++)
    {
        bfs(ii, jj, i);
        if(dis[ei][ej] < 3) {cout<<"YES\n"; ok=1; break;}
    }
    if(!ok) cout<<"NO\n";
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const int MX=1005;
const double PI = acos(-1.0), EPS = 1e-9;
int N, M;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
bool ok(int x, int y)
{
    return x >= 0 && y >= 0 && x < N && y < M;
}
int dis[MX][MX];
string g[MX];
char s[MX];
int save[MX][MX];
deque<pair<int, int> > dq;
void bfs(int i, int j, int dir)
{
    dq.clear();
    memset(save, 0, sizeof save);
    save[i][j]=-1;
    dq.pb(mp(i, j));
    dis[i][j]=0;
    while(dq.size())
    {
        int x=dq.front().F;
        int y=dq.front().S;
        dq.pop_front();
        for(int d=0;d<4;d++)
        {
            int xx=x+dx[d];
            int yy=y+dy[d];
            if(!ok(xx, yy) || g[xx][yy] == '*') continue;
            if(dis[xx][yy] > dis[x][y])
            {
                dis[xx][yy]=dis[x][y];
                if(d == 0 && save[x][y] != 1) dis[xx][yy]++;
                if(d == 1 && save[x][y] != 2) dis[xx][yy]++;
                if(d == 2 && save[x][y] != 3) dis[xx][yy]++;
                if(d == 3 && save[x][y] != 4) dis[xx][yy]++;
                if(d == 0)
                    save[xx][yy]=1;
                else if(d == 1)
                    save[xx][yy]=2;
                else if(d == 2) save[xx][yy]=3;
                else save[xx][yy]=4;
                if(dis[xx][yy] < 4)
                    dq.pb(mp(xx, yy));
            }
        }
    }
}
int main()
{

    scanf("%d %d", &N, &M);
    int ii, jj, ei, ej;
    for(int i=0;i<N;i++)
    {
        scanf("%s", &s);
        g[i]=s;
    }
     for(int i=0;i<=N;i++)
    {
        for(int j=0;j<=M;j++)
        {
            dis[i][j]=1e9;
        }
    }
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
            if(g[i][j] == 'S')
            {
                ii=i;
                jj=j;
            }
            if(g[i][j] == 'T')
            {
                ei=i;
                ej=j;
            }
        }
    }
    bool ok=0;
    bfs(ii, jj, -1);
    if(dis[ei][ej] <= 3) {cout<<"YES\n"; ok=1;}
    if(!ok) cout<<"NO\n";
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const int MX=1005;
const double PI = acos(-1.0), EPS = 1e-9;
int N, M;
struct Node
{
        int w, x, y, p;
        Node(int ww=0, int xx=0, int yy=0, int pp=0)
        {
            x=xx;
            y=yy;
            p=pp;
            w=ww;
        }
        bool operator == (const Node &d) const
        {
            return w == d.w ;
        }
        bool operator < (const Node &d) const
        {
            if(w == d.w)
            {
                return p < d.p;
            }
            return w < d.w;
        }
};
multiset<Node> ms;
int dist[MX][MX];
char g[MX][MX];
int ii, jj, iii, jjj;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
bool ok(int x, int y)
{
    return x >= 0 && y >= 0 && x < N && y < M;
}
int main()
{
    scanf("%d %d", &N, &M);
    for(int i=0;i<N;i++)
    {
        scanf("%s", g[i]);
        for(int j=0;j<M;j++)
        {
            if(g[i][j] == 'S')
            {
                ii=i;
                jj=j;
            }
            if(g[i][j] == 'T')
            {
                iii=i;
                jjj=j;
            }
            dist[i][j]=1e9;
        }
    }
    ms.insert(Node(0, ii, jj, 1e9));
    dist[ii][jj]=0;
    while(ms.size() > 0)
    {
        int cost=ms.begin()->w;
        int xx=ms.begin()->x;
        int yy=ms.begin()->y;
        int pp=ms.begin()->p;
        ms.erase(ms.begin());
        if(dist[xx][yy] < cost) continue;
        for(int d=0;d<4;d++)
        {
            int cx=xx+dx[d];
            int cy=yy+dy[d];
            if(!ok(cx, cy) || g[cx][cy] == '*') continue;
            int add=0;
            if(pp != d) add++;
            if(dist[cx][cy] > dist[xx][yy] + add)
            {
                dist[cx][cy]=dist[xx][yy]+add;
                ms.insert(Node(dist[cx][cy], cx, cy, d));
            }
        }
    }
    if(dist[iii][jjj] < 4) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
const int MX=1234567;
const double PI = acos(-1.0), EPS = 1e-9;
int N, M;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
bool ok(int x, int y)
{
    return x >= 0 && y >= 0 && x < N && y < M;
}
int dis[1112][1112];
char g[1111][1111];
int save[1112][1112];
void bfs(int i, int j)
{
    deque<pair<int, int> > dq;
    memset(save, 0, sizeof save);
    dq.pb(mp(i, j));
    dis[i][j]=0;
    for(int d=0;d<4;d++)
    {
        int ii=i+dx[d];
        int jj=j+dy[d];
        if(ok(ii, jj) && g[ii][jj] != '*')
        {
            dis[ii][jj]=0;
            if(d == 0)
                save[ii][jj]=1;
            else if(d == 1)
                save[ii][jj]=2;
            else if(d == 2) save[ii][jj]=3;
            else save[ii][jj]=4;
            dq.pb(mp(ii, jj));
        }
    }
    while(dq.size())
    {
        int x=dq.front().F;
        int y=dq.front().S;
        dq.pop_front();
        for(int d=0;d<4;d++)
        {
            int xx=x+dx[d];
            int yy=y+dy[d];
            if(!ok(xx, yy) || g[xx][yy] == '*') continue;
            if(dis[xx][yy] > dis[x][y])
            {
                dis[xx][yy]=dis[x][y];
                if(d == 0 && save[x][y] != 1) dis[xx][yy]++;
                if(d == 1 && save[x][y] != 2) dis[xx][yy]++;
                if(d == 2 && save[x][y] != 3) dis[xx][yy]++;
                if(d == 3 && save[x][y] != 4) dis[xx][yy]++;
                if(d == 0)
                    save[xx][yy]=1;
                else if(d == 1)
                    save[xx][yy]=2;
                else if(d == 2) save[xx][yy]=3;
                else save[xx][yy]=4;
                dq.pb(mp(xx, yy));
            }
        }
    }
}
int main()
{
    for(int i=0;i<1111;i++)
    {
        for(int j=0;j<1111;j++)
        {
            dis[i][j]=1e9;
        }
    }
    cin>>N>>M;
    int ii, jj, ei, ej;
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
            cin>>g[i][j];
            if(g[i][j] == 'S')
            {
                ii=i;
                jj=j;
            }
            if(g[i][j] == 'T')
            {
                ei=i;
                ej=j;
            }
        }
    }
    bfs(ii, jj);
   /* for(int i=0;i<N;i++)
    {
        for(int j=0;j<M;j++)
        {
            cout<<dis[i][j]<<" ";
        }
        cout<<"\n";
    }*/
    ///return 0;
    if(dis[ei][ej] < 3) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int last[MAX][MAX][4][3][2];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  a[i][j] = '0';
  for(int k = 0 ; k < 4 and !endgame ; k++){
    if(last[i][j][k][turn][dir]) continue;
    last[i][j][k][turn][dir] = 1;
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*' or a[ddx][ddy] == '0') continue;
      //printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        if(dir and ddx != i) turn++;
        if(!dir and ddy != j)turn++;
        if(turn <= 2){
          cout<<"YES"<<endl;
          endgame = 1;
          return;
        }
        turn--;
        return;
      }
    }
  }
  if(!endgame)
    a[i][j] = '.';
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,1);
  turn = 0;
  if(!endgame)
    run(is,js,0);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int last[MAX][MAX][4][3][2];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  for(int k = 0 ; k < 4 and !endgame ; k++){
    if(last[i][j][k][turn][dir]) continue;
    last[i][j][k][turn][dir] = 1;
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*') continue;
      //printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        endgame = 1;
        cout<<"YES"<<endl;
        return;
      }
    }
  }
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,0);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int last[MAX][MAX][4][3][2];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  //a[i][j] = '0';
  for(int k = 0 ; k < 4 and !endgame ; k++){
    if(last[i][j][k][turn][dir]) continue;
    last[i][j][k][turn][dir] = 1;
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*' or a[ddx][ddy] == '0') continue;
      printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        if(dir and ddx != i) turn++;
        if(!dir and ddy != j)turn++;
        if(turn > 2) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        endgame = 1;
        return;
      }
    }
  }
  //if(!endgame)
    //a[i][j] = '.';
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,1);
  turn = 0;
  if(!endgame)
    run(is,js,0);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int last[MAX][MAX][4][3][2];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  //a[i][j] = '0';
  for(int k = 0 ; k < 4 and !endgame ; k++){
    if(last[i][j][k][turn][dir]) continue;
    last[i][j][k][turn][dir] = 1;
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*' or a[ddx][ddy] == '0') continue;
      //printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        if(dir and ddx != i) turn++;
        if(!dir and ddy != j)turn++;
        if(turn > 2) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        endgame = 1;
        return;
      }
    }
  }
  //if(!endgame)
    //a[i][j] = '.';
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,1);
  turn = 0;
  if(!endgame)
    run(is,js,0);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  a[i][j] = '0';
  for(int k = 0 ; k < 4 and !endgame ; k++){
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*' or a[ddx][ddy] == '0') continue;
      //printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        endgame = 1;
        cout<<"YES"<<endl;
        return;
      }
    }
  }
  if(!endgame)
    a[i][j] = '.';
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,1);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  a[i][j] = '0';
  for(int k = 0 ; k < 4 and !endgame ; k++){
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*' or a[ddx][ddy] == '0') continue;
      //printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        endgame = 1;
        cout<<"YES"<<endl;
        return;
      }
    }
  }
  if(!endgame)
    a[i][j] = '.';
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,1);
  if (!endgame)
    run(is,js,0);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int last[MAX][MAX][4][3][2];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  //a[i][j] = '0';
  for(int k = 0 ; k < 4 and !endgame ; k++){
    if(last[i][j][k][turn][dir]) continue;
    last[i][j][k][turn][dir] = 1;
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*' or a[ddx][ddy] == '0') continue;
      //printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        if(dir and ddx != i) turn++;
        if(!dir and ddy != j)turn++;
        if(turn <= 2){
          cout<<"YES"<<endl;
          endgame = 1;
          return;
        }
        turn--;
        return;
      }
    }
  }
  //if(!endgame)
    //a[i][j] = '.';
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,1);
  turn = 0;
  if(!endgame)
    run(is,js,0);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int last[MAX][MAX][4][3][2];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  for(int k = 0 ; k < 4 and !endgame ; k++){
    if(last[i][j][k][turn][dir]) continue;
    last[i][j][k][turn][dir] = 1;
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*') continue;
      //printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        endgame = 1;
        cout<<"YES"<<endl;
        return;
      }
    }
  }
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,0);
  turn = 0;
  if(!endgame)
    run(is,js,1);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  a[i][j] = '0';
  for(int k = 0 ; k < 4 and !endgame ; k++){
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*' or a[ddx][ddy] == '0') continue;
      //printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        endgame = 1;
        cout<<"YES"<<endl;
        return;
      }
    }
  }
  if(!endgame)
    a[i][j] = '.';
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,0);
  if (!endgame)
    run(is,js,1);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define MAX 1001

char a[MAX][MAX];
int endgame;
int turn;
int n,m;
int last[MAX][MAX][4][3][2];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void run(int i, int j, int dir){
  if(turn > 2 or endgame)
    return;
  int ddx,ddy;
  for(int k = 0 ; k < 4 and !endgame ; k++){
    if(last[i][j][k][turn][dir]) continue;
    last[i][j][k][turn][dir] = 1;
    ddx = i + dx[k];
    ddy = j + dy[k];
    if(min(ddx,ddy) >= 0 and ddx < n and ddy < m){
      if(a[ddx][ddy] == '*') continue;
      //printf("indices anterior%d %d\nindices futuros %d %d\nValor na matriz %c\ndir e turn %d %d\n", i, j, ddx, ddy, a[ddx][ddy], dir, turn);
      if(a[ddx][ddy] == '.'){
        if(dir and ddx != i){
          turn++;
          dir = 0;
          run(ddx,ddy,dir);
          turn--;
          dir = 1;
          continue;
        }
        if(!dir and ddy != j){
          turn++;
          dir = 1;
          run(ddx,ddy,dir);
          turn--;
          dir = 0;
          continue;
        }
        run(ddx,ddy,dir);
      }else if(a[ddx][ddy] == 'T'){
        endgame = 1;
        cout<<"YES"<<endl;
        return;
      }
    }
  }
}

int main(){
  char letter;
  int is,js;
  endgame = 0;
  turn = 0;
  cin>>n>>m;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m ; j++){
      cin>>letter;
      a[i][j] = letter;
      if (letter == 'S'){
        is = i;
        js = j;
      }
    }
  }
  run(is,js,1);
  if(!endgame)
    cout<<"NO"<<endl;
  return 0;

}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
int visit[1005][1005][4];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;
clock_t startTime;
void dfs(ll i, ll j, ll fuck, ll prev, ll parx, ll pary){
//	trace5(i, j, fuck, prev, str[i][j]);

	if(fuck > 2)
		return ;

	if(str[i][j] == 'T'){
		flag="YES";
		cout << flag ;
		exit(0);
		return ;
	}
	if( visit[i][j][prev] > fuck )
		visit[i][j][prev] = fuck;
	else
		return ;
	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(x==parx && y==pary)
			continue;

		if(check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt, i, j);
			} else{
				dfs(x, y, fuck+1, cnt, i, j);
			}
		}
	}

	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	startTime = clock();
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	memset(visit, 10, sizeof(visit));

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, 0, 0, -1, -1);
				dfs(i, j, 0, 1, -1, -1);
				dfs(i, j, 0, 2, -1, -1);
				dfs(i, j, 0, 3, -1, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
int visit[1005][1005];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;
clock_t startTime;
void dfs(ll i, ll j, ll fuck, ll prev){
//	trace5(i, j, fuck, prev, str[i][j]);

	if(fuck > 3)
		return ;

	if(str[i][j] == 'T'){
		flag="YES";
		cout << flag ;
		exit(0);
		return ;
	}
	if( visit[i][j] >= fuck )
		visit[i][j] = fuck;
	else
		return ;
	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt);
			} else{
				dfs(x, y, fuck+1, cnt);
			}
		}
	}

	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	startTime = clock();
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	memset(visit, 10, sizeof(visit));

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, 0, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

string str[1005];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;

bool check(int i, int j){
	if(i <= n && i > 0 && j <=m && j > 0 && str[i][j] != '*')
		return true;
	return false;
}

bool visit[1002][1002][4][3];

void dfs(int i, int j, int dir, int curr){
//	trace5(i, j, dir, curr, str[i][j]);
	if(visit[i][j][dir][curr])
		return ;

	if(curr > 2)
		return ;

	if(str[i][j] == 'T'){
		cout << "YES";
		exit(0);
	}

	for(int k = 0; k<4; k++){
		int x = i + dx[k];
		int y = j + dy[k];

		if(check(x, y)){
			if(k == dir){
				dfs(x, y, k, curr);
			} else{
				dfs(x, y, k, curr+1);
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int i, j;

	cin >> n >> m;

	for(i=1; i<=n; i++){
		cin >> str[i];
		str[i] = "#" + str[i];
	}

	for(i=1; i<=n; i++){
		for(j=1; j<=m; j++){
//			trace3(i, j, str[i][j]);
			if(str[i][j] == 'S'){
				dfs(i, j, 0, 0);
				dfs(i, j, 1, 0);
				dfs(i, j, 2, 0);
				dfs(i, j, 3, 0);
				break;
			}
		}
		if(j != m+1)
			break;
	}

	cout << "NO";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
int visit[1005][1005][4];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;
clock_t startTime;
void dfs(ll i, ll j, ll fuck, ll prev, ll parx, ll pary){
//	trace5(i, j, fuck, prev, str[i][j]);

	if(fuck > 3)
		return ;

	if(str[i][j] == 'T'){
		flag="YES";
		cout << flag ;
		exit(0);
		return ;
	}
	if( visit[i][j][prev] > fuck )
		visit[i][j][prev] = fuck;
	else
		return ;
	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(x==parx && y==pary)
			continue;

		if(check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt, i, j);
			} else{
				dfs(x, y, fuck+1, cnt, i, j);
			}
		}
	}

	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	startTime = clock();
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	memset(visit, 10, sizeof(visit));

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, -1, -1, -1, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

string str[1005];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;

bool check(int i, int j){
	if(i <= n && i > 0 && j <=m && j > 0 && str[i][j] != '*')
		return true;
	return false;
}

bool visit[1002][1002][4][3];

void dfs(int i, int j, int dir, int curr){
//	trace5(i, j, dir, curr, str[i][j]);
	if(visit[i][j][dir][curr])
		return ;

	if(curr > 2)
		return ;

	if(str[i][j] == 'T'){
		cout << "YES";
		exit(0);
	}

	visit[i][j][dir][curr] = 1;

	for(int k = 0; k<4; k++){
		int x = i + dx[k];
		int y = j + dy[k];

		if(check(x, y)){
			if(k == dir){
				dfs(x, y, k, curr);
			} else{
				dfs(x, y, k, curr+1);
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int i, j;

	cin >> n >> m;

	for(i=1; i<=n; i++){
		cin >> str[i];
		str[i] = "#" + str[i];
	}

	for(i=1; i<=n; i++){
		for(j=1; j<=m; j++){
//			trace3(i, j, str[i][j]);
			if(str[i][j] == 'S'){
				dfs(i, j, 0, 0);
				dfs(i, j, 1, 0);
				dfs(i, j, 2, 0);
				dfs(i, j, 3, 0);
				break;
			}
		}
		if(j != m+1)
			break;
	}

	cout << "NO";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

string str[1005];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;

bool check(int i, int j){
	if(i <= n && i > 0 && j <=m && j > 0 && str[i][j] != '*')
		return true;
	return false;
}

bool visit[1002][1002][4][3];

void dfs(int i, int j, int dir, int curr){
	if(visit[i][j][dir][curr])
		return ;

	if(curr > 2)
		return ;

	if(str[i][j] == 'T'){
		cout << "YES";
		exit(0);
	}

	for(int k = 0; k<4; k++){
		int x = i + dx[k];
		int y = j + dy[k];

		if(check(x, y)){
			if(k == dir){
				dfs(x, y, k, curr);
			} else{
				dfs(x, y, k, curr+1);
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int i, j;

	cin >> n >> m;

	for(i=1; i<=n; i++){
		cin >> str[i];
		str[i] = "#" + str[i];
	}

	for(i=1; i<=n; i++){
		for(j=1; j<=m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, 0, 0);
				dfs(i, j, 1, 0);
				dfs(i, j, 2, 0);
				dfs(i, j, 3, 0);
				break;
			}
		}
		if(j != m)
			break;
	}

	cout << "NO";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
int visit[1005][1005][4];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;
clock_t startTime;
void dfs(ll i, ll j, ll fuck, ll prev, ll parx, ll pary){
//	trace5(i, j, fuck, prev, str[i][j]);

	if(fuck > 3)
		return ;

	if(str[i][j] == 'T'){
		flag="YES";
		cout << flag ;
		exit(0);
		return ;
	}
	if( visit[i][j][prev] >= fuck )
		visit[i][j][prev] = fuck;
	else
		return ;
	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(x==parx && y==pary)
			continue;

		if(check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt, i, j);
			} else{
				dfs(x, y, fuck+1, cnt, i, j);
			}
		}
	}

	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	startTime = clock();
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	memset(visit, 10, sizeof(visit));

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, -1, -1, -1, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
bool visit[1005][1005][4];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;
clock_t startTime;
void dfs(ll i, ll j, ll fuck, ll prev){
//	trace5(i, j, fuck, prev, str[i][j]);

	if(fuck > 3)
		return ;

	if(str[i][j] == 'T'){
		flag="YES";
		cout << flag ;
		exit(0);
		return ;
	}

	if(visit[i][j][prev])
		return ;

	visit[i][j][prev] = true;
	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt);
			} else{
				dfs(x, y, fuck+1, cnt);
			}
		}
	}

	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	startTime = clock();
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, 0, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
int visit[1005][1005];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;
clock_t startTime;
void dfs(ll i, ll j, ll fuck, ll prev){
//	trace5(i, j, fuck, prev, str[i][j]);

	if(fuck > 3)
		return ;

	if(str[i][j] == 'T'){
		flag="YES";
		cout << flag ;
		exit(0);
		return ;
	}
	if( visit[i][j] > fuck )
		visit[i][j] = fuck;
	else
		return ;
	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt);
			} else{
				dfs(x, y, fuck+1, cnt);
			}
		}
	}

	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	startTime = clock();
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	memset(visit, 10, sizeof(visit));

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, 0, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
bool visit[1005][1005][4];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;
clock_t startTime;
void dfs(ll i, ll j, ll fuck, ll prev){
//	trace5(i, j, fuck, prev, str[i][j]);

	if(fuck > 3)
		return ;

	if(str[i][j] == 'T'){
		flag="YES";
		cout << flag ;
		exit(0);
		return ;
	}
	visit[i][j][prev] = true;
	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt);
			} else{
				dfs(x, y, fuck+1, cnt);
			}
		}
	}

	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	startTime = clock();
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, 0, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
bool visit[1005][1005];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;

void dfs(ll i, ll j, ll fuck, ll prev){
//	trace5(i, j, fuck, prev, str[i][j]);
	if(fuck > 3)
		return ;

	visit[i][j] = true;

	if(str[i][j] == 'T'){
		flag="YES";
		return ;
	}

	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(!visit[x][y] && check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt);
			} else{
				dfs(x, y, fuck+1, cnt);
			}
		}
	}
	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, 0, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
int visit[1005][1005];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;
clock_t startTime;
void dfs(ll i, ll j, ll fuck, ll prev){
//	trace5(i, j, fuck, prev, str[i][j]);

	if(double( clock() - startTime ) / (double)CLOCKS_PER_SEC > 2.5){
		cout << flag;
		exit(0);
	}

	if(fuck > 3)
		return ;

	if(str[i][j] == 'T'){
		flag="YES";
		cout << flag ;
		exit(0);
		return ;
	}
	if( visit[i][j] >= fuck )
		visit[i][j] = fuck;
	else
		return ;
	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt);
			} else{
				dfs(x, y, fuck+1, cnt);
			}
		}
	}

	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	startTime = clock();
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	memset(visit, 10, sizeof(visit));

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, 0, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;
ll n, m;
string str[1005];

ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
bool visit[1005][1005];

bool check(ll i, ll j){
	if(i >= 0 && i<n && j >= 0 && j < m && str[i][j] != '*')
		return true;
	return false;
}
string flag;
clock_t startTime;
void dfs(ll i, ll j, ll fuck, ll prev){
//	trace5(i, j, fuck, prev, str[i][j]);

	if(double( clock() - startTime ) / (double)CLOCKS_PER_SEC > 2.5){
		cout << flag;
		exit(0);
	}

	if(fuck > 3)
		return ;

	if(str[i][j] == 'T'){
		flag="YES";
		cout << flag ;
		exit(0);
		return ;
	}else{
		visit[i][j] = true;
	}

	for(ll cnt=0; cnt<4; cnt++){
		ll x = i + dx[cnt];
		ll y = j + dy[cnt];

		if(!visit[x][y] && check(x, y)){
			if(prev == cnt){
				dfs(x, y, fuck, cnt);
			} else{
				dfs(x, y, fuck+1, cnt);
			}
		}
	}
	visit[i][j]=false;
	return ;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	startTime = clock();
	flag = "NO";
	cin >> n >> m;
	ll i, j;
	for(i=0; i<n; i++){
		cin >> str[i];
	}

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(str[i][j] == 'S'){
				dfs(i, j, 0, -1);
				break;
			}
		}
		if(j != m)
			break;
	}
	cout << flag;

	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define ii pair<int,int>

using namespace std;
struct data
{
    int x,y,cost,dir;
    data(){}
    data(int _x , int _y , int _cost , int _dir) : x(_x) , y(_y) , cost(_cost) , dir(_dir){}
};
char grid[1002][1002];
int  n,m,sx,sy,dist[1001][1001],gx,gy;
ii mv[4]={mp(1,0),mp(0,1),mp(0,-1),mp(-1,0)};
bool check(int,int),BFS(int,int);

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",grid[i]);
    for(int i=0;i<1000;i++)
        for(int j=0;j<1000;j++)
            dist[i][j]=1000;

    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            if(grid[i][j]=='S')
                sx=i , sy=j;
            else if(grid[i][j]=='T')
                gx=i , gy=j;
        }
    bool res=BFS(sx,sy);
    if(res)
        cout<<"YES";
    else
        cout<<"NO";
}
bool BFS(int x , int y)
{
    dist[x][y]=0;
    deque<data> q;
    for(int k=0;k<4;k++)
    {
        int i=x+mv[k].first , j=y+mv[k].second;
        if(check(i,j))
        {
            dist[i][j]=0;
            q.push_back(data(i,j,0,k));
        }
    }
    while(!q.empty())
    {
        data curr=q.front();
        q.pop_front();
        int i=curr.x , j=curr.y , c=curr.cost , d=curr.dir;
        if(i==gx && j==gy)
            return true;
        if(c<=dist[i][j] && c<=2)
        {
            for(int k=0;k<4;k++)
            {
                int nxt_x=i+mv[k].first,nxt_y=j+mv[k].second,nxt_c=c+(k!=d),nxt_dir=k;
                if(check(nxt_x,nxt_y))
                {
                    if(nxt_c<=dist[nxt_x][nxt_y] && nxt_c<=2)
                    {
                        if(nxt_x==gx && nxt_y==gy)
                            return true;
                        dist[nxt_x][nxt_y]=nxt_c;
                        if(k==d)
                            q.push_front(data(nxt_x,nxt_y,nxt_c,nxt_dir));
                        else
                            q.push_back(data(nxt_x,nxt_y,nxt_c,nxt_dir));
                    }
                }
            }
        }
    }
    return false;
}
bool check(int x , int y)
{
    return (x<n && x>=0 && y<m && y>=0 && grid[x][y]!='*');
}


#include <bits/stdc++.h>
#define mp make_pair
#define ii pair<int,int>

using namespace std;
struct data
{
    int x,y,cost,dir;
    data(){}
    data(int _x , int _y , int _cost , int _dir) : x(_x) , y(_y) , cost(_cost) , dir(_dir){}
};
char grid[1001][1001];
int  n,m,sx=-1,sy=-1,dist[1001][1001] , gx,gy;
ii mv[4]={mp(1,0),mp(0,1),mp(0,-1),mp(-1,0)};
bool check(int,int),BFS(int,int);

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",grid[i]);
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            dist[i][j]=1e8;
            if(grid[i][j]=='S')
                sx=i , sy=j;
            if(grid[i][j]=='T')
                gx=i , gy=j;
        }
    bool res=BFS(sx,sy);
    if(res)
        cout<<"YES";
    else
        cout<<"NO";
}
bool BFS(int x , int y)
{
    dist[x][y]=0;
    queue<data> q;
    for(int k=0;k<4;k++)
    {
        int i=x+mv[k].first , j=y+mv[k].second;
        if(check(i,j))
            q.push(data(i,j,0,k));
    }
    while(!q.empty())
    {
        data curr=q.front();
        q.pop();
        int i=curr.x , j=curr.y , c=curr.cost , d=curr.dir;
        if(i==gx && j==gy)
            return true;
        if(dist[i][j]>c)
        {
            dist[i][j]=c;
            for(int k=0;k<4;k++)
            {
                int nxt_x=i+mv[k].first,nxt_y=j+mv[k].second,nxt_c=c+(k!=d),nxt_dir=k;
                if(check(nxt_x,nxt_y))
                {
                    if(nxt_c<3)
                    {
                        if(nxt_x==gx && nxt_y==gy)
                            return true;
                        q.push(data(nxt_x,nxt_y,nxt_c,nxt_dir));
                    }
                }
            }
        }
    }
    return false;
}
bool check(int x , int y)
{
    return (x<n && x>=0 && y<m && y>=0 && grid[x][y]!='*');
}


#include <bits/stdc++.h>
#define mp make_pair
#define ii pair<int,int>

using namespace std;
struct data
{
    int x,y,cost,dir;
    data(){}
    data(int _x , int _y , int _cost , int _dir) : x(_x) , y(_y) , cost(_cost) , dir(_dir){}
};
char grid[1002][1002];
int  n,m,sx,sy,dist[1001][1001],gx,gy;
ii mv[4]={mp(1,0),mp(0,1),mp(0,-1),mp(-1,0)};
bool check(int,int),BFS(int,int);

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",grid[i]);
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            dist[i][j]=10;
            if(grid[i][j]=='S')
                sx=i , sy=j;
            if(grid[i][j]=='T')
                gx=i , gy=j;
        }
    bool res=BFS(sx,sy);
    if(res)
        cout<<"YES";
    else
        cout<<"NO";
}
bool BFS(int x , int y)
{
    dist[x][y]=0;
    queue<data> q;
    for(int k=0;k<4;k++)
    {
        int i=x+mv[k].first , j=y+mv[k].second;
        if(check(i,j))
            q.push(data(i,j,0,k));
    }
    while(!q.empty())
    {
        data curr=q.front();
        q.pop();
        int i=curr.x , j=curr.y , c=curr.cost , d=curr.dir;
        if(i==gx && j==gy)
            return true;
        if(c<dist[i][j] && c<=2)
        {
            dist[i][j]=c;
            for(int k=0;k<4;k++)
            {
                int nxt_x=i+mv[k].first,nxt_y=j+mv[k].second,nxt_c=c+(k!=d),nxt_dir=k;
                if(check(nxt_x,nxt_y))
                {
                    if(nxt_c<dist[nxt_x][nxt_y] && nxt_c<=2)
                    {
                        if(nxt_x==gx && nxt_y==gy)
                            return true;
                        q.push(data(nxt_x,nxt_y,nxt_c,nxt_dir));
                    }
                }
            }
        }
    }
    return false;
}
bool check(int x , int y)
{
    return (x<n && x>=0 && y<m && y>=0 && grid[x][y]!='*');
}


#include <bits/stdc++.h>
#define mp make_pair
#define ii pair<int,int>

using namespace std;
struct data
{
    int x,y,cost,dir;
    data(){}
    data(int _x , int _y , int _cost , int _dir) : x(_x) , y(_y) , cost(_cost) , dir(_dir){}
};
char grid[1002][1002];
int  n,m,sx,sy,dist[1001][1001],gx,gy;
ii mv[4]={mp(1,0),mp(0,1),mp(0,-1),mp(-1,0)};
bool check(int,int),BFS(int,int);

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",grid[i]);
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            dist[i][j]=10;
            if(grid[i][j]=='S')
                sx=i , sy=j;
            if(grid[i][j]=='T')
                gx=i , gy=j;
        }
    bool res=BFS(sx,sy);
    if(res)
        cout<<"YES";
    else
        cout<<"NO";
}
bool BFS(int x , int y)
{
    dist[x][y]=0;
    deque<data> q;
    for(int k=0;k<4;k++)
    {
        int i=x+mv[k].first , j=y+mv[k].second;
        if(check(i,j))
            q.push_back(data(i,j,0,k));
    }
    while(!q.empty())
    {
        data curr=q.front();
        q.pop_front();
        int i=curr.x , j=curr.y , c=curr.cost , d=curr.dir;
        if(i==gx && j==gy)
            return true;
        if(c<dist[i][j] && c<=2)
        {
            for(int k=0;k<4;k++)
            {
                int nxt_x=i+mv[k].first,nxt_y=j+mv[k].second,nxt_c=c+(k!=d),nxt_dir=k;
                if(check(nxt_x,nxt_y))
                {
                    if(nxt_c<dist[nxt_x][nxt_y] && nxt_c<=2)
                    {
                        if(nxt_x==gx && nxt_y==gy)
                            return true;
                        if(k==d)
                            q.push_front(data(nxt_x,nxt_y,nxt_c,nxt_dir));
                        else
                            q.push_back(data(nxt_x,nxt_y,nxt_c,nxt_dir));
                    }
                }
            }
        }
    }
    return false;
}
bool check(int x , int y)
{
    return (x<n && x>=0 && y<m && y>=0 && grid[x][y]!='*');
}