#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef vector<ll>vi;
typedef pair<ll,ll>pi;
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
ll max(ll a,ll b){return (a>b?a:b);}
ll min(ll a,ll b){return (a<b?a:b);}
ll gcd(ll a,ll b)
{return (b?gcd(b,a%b):a);
}
void algo()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll t=0,m=0;
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]=='T')
            t++;
        else
            m++;
    }
    if(2*m!=t)
        cout<<"NO";
    else
    {
        t=0,m=0;
        for(ll i=0;i<n;i++)
        {
            if(s[i]=='T')
                t++;
            else
            {
                m++;
                if(m>t)
                {
                    cout<<"NO";
                    return;
                }
            }
        }
        t=0;m=0;
        for(ll i=n-1;i>=0;i--)
        {
            if(s[i]=='T')
                t++;
            else
            {
                m++;
                if(m>t)
                {
                    cout<<"NO";
                    return;
                }
            }
        }
        cout<<"YES";
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<setprecision(20);
    ll t;cin>>t;
    while(t--)
    {
        algo();
	cout<<"\n";
    }
    return 0;
}
