#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector< ll > vl;
typedef vector< vector< ll > > vvl;
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);   cout.tie(NULL);
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c,it) for(auto it=(c).begin(); it!=(c).end(); it++)
#define ref(i,n)    for(i=0;i<n;i++)
#define mp make_pair
#define endl "\n"
#define MOD 1000000007
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}

int main()
{
    boost
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,x=0,y=0,flag=0,m,i;
        cin>>n;
        string s;
        cin>>s;
        ref(i,n)
        {
            if(s[i]=='T')
                x++;
            else
            {
                y++;
            }
            if(y>x)
            {
                flag=1;
                break;
            }
        }
        if(flag==1 || x!=2*y)
        {
            cout<<"NO"<<endl;
            continue;
        }
        x=y=flag=0;
        for(i=n-1;i>=0;i--)
        {
            if(s[i]=='T')
                x++;
            else
            {
                y++;
            }
            if(y>x)
            {
                flag=1;
                break;
            }
        }
        if(flag)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}


