#include<bits/stdc++.h>
#define maxn 1000005
#define inf 0x3f3f3f3f
#define mod 1000000007
#define mst(a,x) memset(a,x,sizeof(a))
#define up(l,r,i) for(LL i=l;i<=r;i++)
#define down(l,r,i) for(LL i=l;i>=r;i--)
#define in(l,r,a) for(LL i=l;i<=r;i++)cin>>a[i]
#define out(l,r,a) for(LL i=l;i<=r;i++)cout<<a[i]<<" "
#define injz(n,m,a) for(LL i=1;i<=n;i++)for(LL j=1;j<=m;j++)cin>>a[i][j]
#define st(a,n) sort(a+1,a+n+1)
#define endl "\n"
#define hh cout<<endl
#define pb push_back
#define cf cin>>T;while(T--)
#define xh(n) U=n;while(U--)
#define cfout(x) cout<<(x?"YES":"NO")<<endl
#define cs cout<<"qaq"<<endl
typedef long long LL;LL T,U;
typedef double db;
using namespace std;
LL a[maxn];
vector<LL>a1,b;
int main()
{
    ios::sync_with_stdio(false);
    //freopen("bwxnQAQin.txt","r",stdin);
    //freopen("bwxnQAQout.txt","w",stdout);
    cf
    {
        string s;
        LL len;
        cin>>len>>s;
        LL now=0,sumt=0,summ=0,ok=1;
        up(0,len-1,i)
        {
            if(s[i]=='T')
            {
                now++;
                sumt++;
            }
            else
            {
                now--;
                summ++;
                if(now<0)ok=0;
            }
        }
        now=0;
        if(summ*2!=sumt)ok=0;
        down(len-1,0,i)
        {
            if(s[i]=='T')now++;
            else
            {
                now--;
                if(now<0)ok=0;
            }
        }
        cfout(ok);
    }
    return 0;
}
