#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int t=0,m=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='T')
                t++;
            else
                m++;
            if(m>t)
            {
             cout<<"NO"<<endl;
             break;
            }
        }
        if(m>t)
            {
             continue;
            }
        else if(t!=2*m)
        {
             cout<<"NO"<<endl;
             continue;
        }
        int t1=0,m1=0;
        for(int i=n-1;i>=0;i--)
        {
            if(s[i]=='T')
                t1++;
            else
                m1++;
            if(m1>t1)
            {
             cout<<"NO"<<endl;
             break;
            }
        }
        if(m1>t1)
            {
             continue;
            }
            cout<<"YES"<<endl;
    }

    return 0 ;
}
