#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define srt(s) sort(s.begin(),s.end())
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll x=0;
        ll p=0,p1=0;
        ll mark=0;
        stack<char>st,st1;
        for(int i=0; i<n; i++)
        {
            if(s[i]=='M')
            {
                x++;
            }
        }
        if(3*x!=n)
        {
            mark=1;
        }
        for(int i=0; i<n; i++)
        {
            if(s[i]=='T')
            {
                st.push(s[i]);
            }
            else
            {
                if(st.size()>0)
                {
                    st.pop();
                }
                else
                {
                    mark=1;
                    break;
                }
            }
        }
        for(int i=n-1; i>=0; i--)
        {
            if(s[i]=='T')
            {
                st1.push(s[i]);
            }
            else
            {
                if(st1.size()>0)
                {
                    st1.pop();
                }
                else
                {
                    mark=1;
                    break;
                }
            }
        }
        if(mark==0)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
}
