#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int t; cin>>t;
    while (t--)
    {
        int n; cin>>n;
        char c[n];
        bool fl=1;
        int km=0;
        for (int i=0;i<n;i++){
            cin>>c[i];
            if (c[i]=='M')
                km++;
        }
        if (km!=n/3)
            fl=0;
        int k=0,j=0;
        for (int i=0;i<n and j<km and fl;i++){
            if (c[i]=='M'){
                j++;
                k--;
            }
            if (c[i]=='T')
                k++;
            if (k<0)
                fl=0;
        }
        if (k<0)
            fl=0;
        k=0;
        j=0;
        for (int i=n-1;i>=0 and j<km and fl;i--){
            if (c[i]=='M'){
                j++;
                k--;
            }
            if (c[i]=='T')
                k++;
            if (k<0)
                fl=0;
        }
        if (k<0)
            fl=0;
        if (fl)
            cout<<"YES";
        else
            cout<<"NO";
        cout<<endl;
    }
}
