#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h> 
#include <random>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define iterate(x) for(auto itr=x.begin(); itr != x.end(); ++itr)
ll myceil(ll a,ll b) { if(a%b == 0) return a/b; else return a/b+1; }
bool isPerSquare(long double a) {if(a<0) return false; ll sr = sqrt(a); return (sr*sr == a);}
 
 

ll arr1[200002];
ll arr2[200002];
ll arr2D[1001][1001];
vector<ll> vec;
 
void solve(){
    ll n,m,a=0,b,c=0,d;
    string s;

    cin >> n;
    //n = 3*(1 + rand()%5);

    cin >> s;

    // forn(i,n)
    // {
    //     ll p = rand()%2;
    //     if(p == 0) s += 'T';
    //     else s += 'M';
    // }
    //cout << s << endl;

    forn(i,n)
    {
        if(s[i] == 'T') a++;
        if(s[i] == 'M') b = i;
    }
    ll p = (2*n)/3;

    if(a != p)
    {
        cout << "NO" << endl;
        return;
    }

    arr1[0] = 0;
    arr2[n+1] = 0;

    forn(i,n)
    {
        if(s[i] == 'T') arr1[i+1] = arr1[i]+1;
        else arr1[i+1] = arr1[i];
    }
    rforsn(i,n,1)
    {
        if(s[i] == 'T') arr2[i] = arr2[i+1]+1;
        else arr2[i] = arr2[i+1];
    }

    ll k = 1;

    forn(i,n)
    {
        if(s[i] == 'M')
        {
            if(arr1[i+1] < k)
            {
                cout << "NO" << endl;
                return;
            }
            k++;
        }
    }

    k =1;

    rforn(i,n-1)
    {
        if(s[i] == 'M')
        {
            if(arr2[i+1] < k)
            {
                cout << "NO" << endl;
                return;
            }
            k++;
        }
    }



    cout << "YES" << endl;

}
int main()
{
 fast_cin();
 ll t = 1;
 cin >> t;
 for(int it=1;it<=t;it++) {
     //cout << "Case #" << it+1 << ": ";
     solve();
 }
 return 0;
}